Class: Uniword::Diff::Semantic::Change

Inherits:
Object
  • Object
show all
Defined in:
lib/uniword/diff/semantic/change.rb

Overview

One classified change. Severity defaults to :info; classifiers can promote to :warning or :error.

Constant Summary collapse

KINDS =
%i[added removed modified moved].freeze
MODIFIERS =
%i[text format structure].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kind:, modifier: nil, old_index: nil, new_index: nil, description: nil) ⇒ Change

Returns a new instance of Change.

Parameters:

  • kind (Symbol)
  • modifier (Symbol, nil) (defaults to: nil)
  • old_index (Integer, nil) (defaults to: nil)
  • new_index (Integer, nil) (defaults to: nil)
  • description (String, nil) (defaults to: nil)


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/uniword/diff/semantic/change.rb', line 34

def initialize(kind:, modifier: nil, old_index: nil,
               new_index: nil, description: nil)
  unless KINDS.include?(kind)
    raise ArgumentError,
          "unknown kind #{kind.inspect}"
  end
  if modifier && !MODIFIERS.include?(modifier)
    raise ArgumentError, "unknown modifier #{modifier.inspect}"
  end

  @kind = kind
  @modifier = modifier
  @old_index = old_index
  @new_index = new_index
  @description = description
end

Instance Attribute Details

#descriptionString? (readonly)

Returns human-readable summary.

Returns:

  • (String, nil)

    human-readable summary



27
28
29
# File 'lib/uniword/diff/semantic/change.rb', line 27

def description
  @description
end

#kindSymbol (readonly)

Returns one of KINDS.

Returns:

  • (Symbol)

    one of KINDS



13
14
15
# File 'lib/uniword/diff/semantic/change.rb', line 13

def kind
  @kind
end

#modifierSymbol? (readonly)

Returns for :modified, one of MODIFIERS.

Returns:

  • (Symbol, nil)

    for :modified, one of MODIFIERS



16
17
18
# File 'lib/uniword/diff/semantic/change.rb', line 16

def modifier
  @modifier
end

#new_indexInteger? (readonly)

Returns paragraph index in new (nil when the paragraph was removed).

Returns:

  • (Integer, nil)

    paragraph index in new (nil when the paragraph was removed)



24
25
26
# File 'lib/uniword/diff/semantic/change.rb', line 24

def new_index
  @new_index
end

#old_indexInteger? (readonly)

Returns paragraph index in old (nil when the paragraph is new).

Returns:

  • (Integer, nil)

    paragraph index in old (nil when the paragraph is new)



20
21
22
# File 'lib/uniword/diff/semantic/change.rb', line 20

def old_index
  @old_index
end

Instance Method Details

#==(other) ⇒ Boolean

Parameters:

  • other (Object)

Returns:

  • (Boolean)


60
61
62
# File 'lib/uniword/diff/semantic/change.rb', line 60

def ==(other)
  other.is_a?(Change) && to_h == other.to_h
end

#to_hHash

Returns:

  • (Hash)


52
53
54
55
56
# File 'lib/uniword/diff/semantic/change.rb', line 52

def to_h
  { kind: kind, modifier: modifier,
    old_index: old_index, new_index: new_index,
    description: description }
end