Class: Diff::Display::Line
- Inherits:
-
String
- Object
- String
- Diff::Display::Line
- Defined in:
- lib/diff/display/data_structure.rb
Overview
Every line from the passed in diff gets transformed into an instance of one of line Line class’s subclasses. One subclass exists for each line type in a diff. As such there is an AddLine class for added lines, a RemLine class for removed lines, an UnModLine class for lines which remain unchanged and a SepLine class which represents all the lines that aren’t part of the diff.
Direct Known Subclasses
AddLine, HeaderLine, NonewlineLine, RemLine, SepLine, UnModLine
Instance Attribute Summary collapse
-
#new_number ⇒ Object
readonly
Returns the value of attribute new_number.
-
#old_number ⇒ Object
readonly
Returns the value of attribute old_number.
Class Method Summary collapse
- .add(line, line_number, inline = false) ⇒ Object
- .header(line) ⇒ Object
- .nonewline(line) ⇒ Object
- .rem(line, line_number, inline = false) ⇒ Object
- .unmod(line, old_number, new_number) ⇒ Object
Instance Method Summary collapse
-
#expand_inline_changes_with(prefix, postfix) ⇒ Object
Expand any inline changes with
prefix
andpostfix
. - #identifier ⇒ Object
-
#initialize(line, old_number = nil, new_number = nil) ⇒ Line
constructor
A new instance of Line.
- #inline_changes? ⇒ Boolean
- #inspect ⇒ Object
-
#segments ⇒ Object
returns the prefix, middle and postfix parts of a line with inline changes.
Constructor Details
#initialize(line, old_number = nil, new_number = nil) ⇒ Line
Returns a new instance of Line.
77 78 79 80 81 |
# File 'lib/diff/display/data_structure.rb', line 77 def initialize(line, old_number = nil, new_number = nil) super(line) @old_number, @new_number = old_number, new_number @inline = false end |
Instance Attribute Details
#new_number ⇒ Object (readonly)
Returns the value of attribute new_number.
82 83 84 |
# File 'lib/diff/display/data_structure.rb', line 82 def new_number @new_number end |
#old_number ⇒ Object (readonly)
Returns the value of attribute old_number.
82 83 84 |
# File 'lib/diff/display/data_structure.rb', line 82 def old_number @old_number end |
Class Method Details
.add(line, line_number, inline = false) ⇒ Object
56 57 58 |
# File 'lib/diff/display/data_structure.rb', line 56 def add(line, line_number, inline = false) AddLine.new(line, line_number, inline) end |
.header(line) ⇒ Object
72 73 74 |
# File 'lib/diff/display/data_structure.rb', line 72 def header(line) HeaderLine.new(line) end |
.nonewline(line) ⇒ Object
68 69 70 |
# File 'lib/diff/display/data_structure.rb', line 68 def nonewline(line) NonewlineLine.new(line) end |
Instance Method Details
#expand_inline_changes_with(prefix, postfix) ⇒ Object
Expand any inline changes with prefix
and postfix
102 103 104 105 106 107 108 |
# File 'lib/diff/display/data_structure.rb', line 102 def (prefix, postfix) return self.dup unless inline_changes? str = self.dup str.sub!('\\0', prefix.to_s) str.sub!('\\1', postfix.to_s) str end |
#identifier ⇒ Object
84 85 86 |
# File 'lib/diff/display/data_structure.rb', line 84 def identifier self.class.name[/\w+$/].gsub(/Line$/, "").downcase.to_sym end |
#inline_changes? ⇒ Boolean
88 89 90 91 |
# File 'lib/diff/display/data_structure.rb', line 88 def inline_changes? # Is set in the AddLine+RemLine subclasses @inline end |
#inspect ⇒ Object
110 111 112 |
# File 'lib/diff/display/data_structure.rb', line 110 def inspect %Q{#<#{self.class.name} [#{old_number.inspect}-#{new_number.inspect}] "#{self}">} end |
#segments ⇒ Object
returns the prefix, middle and postfix parts of a line with inline changes
94 95 96 97 98 99 |
# File 'lib/diff/display/data_structure.rb', line 94 def segments return self.dup unless inline_changes? prefix, changed = self.dup.split('\\0') changed, postfix = changed.split('\\1') [prefix, changed, postfix] end |