Class: PrettyDiff::Line
Overview
Represent a single line of the diff.
Instance Attribute Summary collapse
-
#diff ⇒ Object
readonly
:nodoc:.
-
#input ⇒ Object
readonly
:nodoc:.
Instance Method Summary collapse
- #added? ⇒ Boolean
- #deleted? ⇒ Boolean
-
#format ⇒ Object
Prepare Line contents for injection into HTML structure.
-
#ignore? ⇒ Boolean
Unified Diff sometimes emit a special line at the end of the file that we should not display in the output.
-
#initialize(diff, input) ⇒ Line
constructor
A new instance of Line.
- #not_modified? ⇒ Boolean
-
#status ⇒ Object
Return status of the Line.
-
#to_html ⇒ Object
Generate HTML presentation for a Line.
Constructor Details
#initialize(diff, input) ⇒ Line
Returns a new instance of Line.
8 9 10 11 |
# File 'lib/pretty_diff/line.rb', line 8 def initialize(diff, input) @diff = diff @input = input end |
Instance Attribute Details
#input ⇒ Object (readonly)
:nodoc:
6 7 8 |
# File 'lib/pretty_diff/line.rb', line 6 def input @input end |
Instance Method Details
#added? ⇒ Boolean
44 45 46 |
# File 'lib/pretty_diff/line.rb', line 44 def added? status == :added end |
#deleted? ⇒ Boolean
48 49 50 |
# File 'lib/pretty_diff/line.rb', line 48 def deleted? status == :deleted end |
#format ⇒ Object
Prepare Line contents for injection into HTML structure. Currently used for replacing Tab symbols with spaces. Return a string.
21 22 23 |
# File 'lib/pretty_diff/line.rb', line 21 def format input.gsub("\t", ' ') end |
#ignore? ⇒ Boolean
Unified Diff sometimes emit a special line at the end of the file that we should not display in the output. Return true or false.
28 29 30 |
# File 'lib/pretty_diff/line.rb', line 28 def ignore? input =~ /\\ No newline at end of file/ end |
#not_modified? ⇒ Boolean
52 53 54 |
# File 'lib/pretty_diff/line.rb', line 52 def not_modified? status == :not_modified end |
#status ⇒ Object
Return status of the Line. Can be :added, :deleted or :not_modified.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/pretty_diff/line.rb', line 33 def status case input when /^\+/ :added when /^\-/ :deleted else :not_modified end end |
#to_html ⇒ Object
Generate HTML presentation for a Line. Return a string.
14 15 16 |
# File 'lib/pretty_diff/line.rb', line 14 def to_html generator.generate end |