Class: Olelo::PatchParser::ChangeHandler

Inherits:
Handler show all
Defined in:
lib/olelo/patch.rb

Direct Known Subclasses

Olelo::PatchFormatter

Instance Method Summary collapse

Methods inherited from Handler

#begin!, #binary!, #context!, #deleted!, #deletion!, #finalize!, #initialize!, #insertion!, #no_changes!, #separator!

Methods included from Util

#check, #decode64, #deep_copy, #encode64, #escape, #escape_html, #escape_javascript, included, #md5, #no_cache?, #sha256, #titlecase, #truncate, #unescape, #unescape_backslash, #unescape_html, #valid_xml_chars?

Instance Method Details

#change!(deletion, insertion) ⇒ Object



76
77
78
79
# File 'lib/olelo/patch.rb', line 76

def change!(deletion, insertion)
  deletion!(deletion)
  insertion!(insertion)
end

#end!Object



72
73
74
# File 'lib/olelo/patch.rb', line 72

def end!
  handle_change
end

#line!(line) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/olelo/patch.rb', line 81

def line!(line)
  ch = line[0..0]
  case ch
  when '@'
    handle_change
    separator!
  when '+'
    handle_change if @deletion && @first == '+'
    @first ||= '+'
    (@insertion ||= '') << line[1..-1] << "\n"
  when '-'
    handle_change if @insertion && @first == '-'
    @first ||= '-'
    (@deletion ||= '') << line[1..-1] << "\n"
  when ' '
    handle_change
    context!(line[1..-1] + "\n")
  end
end