Class: MailDiff::Line

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

Overview

Represent a single line of the diff.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(diff, content) ⇒ Line

Returns a new instance of Line.



9
10
11
12
# File 'lib/mail_diff/line.rb', line 9

def initialize(diff, content)
  @diff = diff
  @content = content
end

Instance Attribute Details

#contentObject (readonly)

:nodoc:



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

def content
  @content
end

#diffObject (readonly)

:nodoc:



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

def diff
  @diff
end

#left_numberObject

Returns the value of attribute left_number.



7
8
9
# File 'lib/mail_diff/line.rb', line 7

def left_number
  @left_number
end

#right_numberObject

Returns the value of attribute right_number.



7
8
9
# File 'lib/mail_diff/line.rb', line 7

def right_number
  @right_number
end

Instance Method Details

#added?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/mail_diff/line.rb', line 45

def added?
  status == :added
end

#deleted?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/mail_diff/line.rb', line 49

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.



22
23
24
# File 'lib/mail_diff/line.rb', line 22

def format
  content.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)


29
30
31
# File 'lib/mail_diff/line.rb', line 29

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

#not_modified?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/mail_diff/line.rb', line 53

def not_modified?
  status == :not_modified
end

#statusObject

Return status of the Line. Can be :added, :deleted or :not_modified.



34
35
36
37
38
39
40
41
42
43
# File 'lib/mail_diff/line.rb', line 34

def status
  case content
  when /^\+/
    :added
  when /^\-/
    :deleted
  else
    :not_modified
  end
end

#to_htmlObject

Generate HTML presentation for a Line. Return a string.



15
16
17
# File 'lib/mail_diff/line.rb', line 15

def to_html
  generator.generate
end