Class: Canon::Diff::DiffLine
- Inherits:
-
Object
- Object
- Canon::Diff::DiffLine
- Defined in:
- lib/canon/diff/diff_line.rb
Overview
Represents a single line in the diff output Links textual representation to semantic DiffNode
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#diff_node ⇒ Object
readonly
Returns the value of attribute diff_node.
-
#line_number ⇒ Object
readonly
Returns the value of attribute line_number.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#added? ⇒ Boolean
True if this line was added.
-
#changed? ⇒ Boolean
True if this line was changed.
-
#formatting? ⇒ Boolean
Formatting diffs are purely cosmetic (whitespace, line breaks) with no semantic meaning.
-
#informative? ⇒ Boolean
If diff_node is nil (not linked), it’s not informative either (it’s unchanged/cosmetic) Formatting-only diffs are never informative.
-
#initialize(line_number:, content:, type:, diff_node: nil, formatting: false) ⇒ DiffLine
constructor
A new instance of DiffLine.
-
#normative? ⇒ Boolean
If diff_node is nil (not linked to any semantic difference), the line is considered informative (cosmetic/unchanged) Formatting-only diffs are never normative.
-
#removed? ⇒ Boolean
True if this line was removed.
- #to_h ⇒ Object
-
#unchanged? ⇒ Boolean
True if this line is unchanged.
Constructor Details
#initialize(line_number:, content:, type:, diff_node: nil, formatting: false) ⇒ DiffLine
Returns a new instance of DiffLine.
15 16 17 18 19 20 21 22 |
# File 'lib/canon/diff/diff_line.rb', line 15 def initialize(line_number:, content:, type:, diff_node: nil, formatting: false) @line_number = line_number @content = content @type = type @diff_node = diff_node @formatting = formatting end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
8 9 10 |
# File 'lib/canon/diff/diff_line.rb', line 8 def content @content end |
#diff_node ⇒ Object (readonly)
Returns the value of attribute diff_node.
8 9 10 |
# File 'lib/canon/diff/diff_line.rb', line 8 def diff_node @diff_node end |
#line_number ⇒ Object (readonly)
Returns the value of attribute line_number.
8 9 10 |
# File 'lib/canon/diff/diff_line.rb', line 8 def line_number @line_number end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
8 9 10 |
# File 'lib/canon/diff/diff_line.rb', line 8 def type @type end |
Instance Method Details
#==(other) ⇒ Object
83 84 85 86 87 88 89 90 |
# File 'lib/canon/diff/diff_line.rb', line 83 def ==(other) other.is_a?(DiffLine) && line_number == other.line_number && content == other.content && type == other.type && diff_node == other.diff_node && @formatting == other.instance_variable_get(:@formatting) end |
#added? ⇒ Boolean
Returns true if this line was added.
57 58 59 |
# File 'lib/canon/diff/diff_line.rb', line 57 def added? type == :added end |
#changed? ⇒ Boolean
Returns true if this line was changed.
67 68 69 |
# File 'lib/canon/diff/diff_line.rb', line 67 def changed? type == :changed end |
#formatting? ⇒ Boolean
Formatting diffs are purely cosmetic (whitespace, line breaks) with no semantic meaning
47 48 49 |
# File 'lib/canon/diff/diff_line.rb', line 47 def formatting? @formatting == true end |
#informative? ⇒ Boolean
If diff_node is nil (not linked), it’s not informative either (it’s unchanged/cosmetic) Formatting-only diffs are never informative
38 39 40 41 42 43 |
# File 'lib/canon/diff/diff_line.rb', line 38 def informative? return false if formatting? return false if diff_node.nil? diff_node.informative? end |
#normative? ⇒ Boolean
If diff_node is nil (not linked to any semantic difference), the line is considered informative (cosmetic/unchanged) Formatting-only diffs are never normative
28 29 30 31 32 33 |
# File 'lib/canon/diff/diff_line.rb', line 28 def normative? return false if formatting? return false if diff_node.nil? diff_node.normative? end |
#removed? ⇒ Boolean
Returns true if this line was removed.
62 63 64 |
# File 'lib/canon/diff/diff_line.rb', line 62 def removed? type == :removed end |
#to_h ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/canon/diff/diff_line.rb', line 71 def to_h { line_number: line_number, content: content, type: type, diff_node: diff_node&.to_h, normative: normative?, informative: informative?, formatting: formatting?, } end |
#unchanged? ⇒ Boolean
Returns true if this line is unchanged.
52 53 54 |
# File 'lib/canon/diff/diff_line.rb', line 52 def unchanged? type == :unchanged end |