Class: Uniword::Diff::Semantic::Change
- Inherits:
-
Object
- Object
- Uniword::Diff::Semantic::Change
- 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
-
#description ⇒ String?
readonly
Human-readable summary.
-
#kind ⇒ Symbol
readonly
One of KINDS.
-
#modifier ⇒ Symbol?
readonly
For :modified, one of MODIFIERS.
-
#new_index ⇒ Integer?
readonly
Paragraph index in new (nil when the paragraph was removed).
-
#old_index ⇒ Integer?
readonly
Paragraph index in old (nil when the paragraph is new).
Instance Method Summary collapse
- #==(other) ⇒ Boolean
-
#initialize(kind:, modifier: nil, old_index: nil, new_index: nil, description: nil) ⇒ Change
constructor
A new instance of Change.
- #to_h ⇒ Hash
Constructor Details
#initialize(kind:, modifier: nil, old_index: nil, new_index: nil, description: nil) ⇒ Change
Returns a new instance of Change.
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
#description ⇒ String? (readonly)
Returns human-readable summary.
27 28 29 |
# File 'lib/uniword/diff/semantic/change.rb', line 27 def description @description end |
#kind ⇒ Symbol (readonly)
Returns one of KINDS.
13 14 15 |
# File 'lib/uniword/diff/semantic/change.rb', line 13 def kind @kind end |
#modifier ⇒ Symbol? (readonly)
Returns for :modified, one of MODIFIERS.
16 17 18 |
# File 'lib/uniword/diff/semantic/change.rb', line 16 def modifier @modifier end |
#new_index ⇒ Integer? (readonly)
Returns 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_index ⇒ Integer? (readonly)
Returns 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
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_h ⇒ 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 |