Class: MailDiff::Diff

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

Overview

Main class to interact with. In fact this is the only class you should interact with when using the library.

Usage example

mail_diff = MailDiff::Diff.new(udiff)
mail_diff.to_html

Keep in mind that Diff will automatically escape all HTML tags from the intput string so that it doesn’t interfere with the output.

Constant Summary collapse

CHUNK_REGEXP =
/@@ .+ @@\n/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(unified_diff, options = {}) ⇒ Diff

Create new Diff object. Accept a String in unified diff format and options hash.



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

def initialize(unified_diff, options={})
  @input = escape_html(unified_diff)
  @options = options
end

Instance Attribute Details

#inputObject (readonly)

Returns the value of attribute input.



17
18
19
# File 'lib/mail_diff/diff.rb', line 17

def input
  @input
end

#optionsObject (readonly)

Returns the value of attribute options.



17
18
19
# File 'lib/mail_diff/diff.rb', line 17

def options
  @options
end

Instance Method Details

#chunksObject

Return an array of Chunk objects that Diff found in the input.



32
33
34
# File 'lib/mail_diff/diff.rb', line 32

def chunks
  @_chunks ||= find_chunks(input)
end

#to_htmlObject

Generate HTML presentation. Return a string.



27
28
29
# File 'lib/mail_diff/diff.rb', line 27

def to_html    
  generator.generate
end