Class: PrettyDiff::Line

Inherits:
Object show all
Defined in:
lib/pretty_diff/line.rb

Overview

Represent a single line of the diff.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#diffObject (readonly)

:nodoc:



6
7
8
# File 'lib/pretty_diff/line.rb', line 6

def diff
  @diff
end

#inputObject (readonly)

:nodoc:



6
7
8
# File 'lib/pretty_diff/line.rb', line 6

def input
  @input
end

Instance Method Details

#added?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/pretty_diff/line.rb', line 44

def added?
  status == :added
end

#deleted?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/pretty_diff/line.rb', line 48

def deleted?
  status == :deleted
end

#formatObject

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.

Returns:

  • (Boolean)


28
29
30
# File 'lib/pretty_diff/line.rb', line 28

def ignore?
  input =~ /\\ No newline at end of file/
end

#not_modified?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/pretty_diff/line.rb', line 52

def not_modified?
  status == :not_modified
end

#statusObject

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_htmlObject

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