Class: AsciiDataTools::Filter::Diffing::Difference

Inherits:
Object
  • Object
show all
Defined in:
lib/ascii-data-tools/filter/diffing.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(left_range, right_range) ⇒ Difference

Returns a new instance of Difference.



59
60
61
62
63
# File 'lib/ascii-data-tools/filter/diffing.rb', line 59

def initialize(left_range, right_range)
  @left_range, @right_range = left_range, right_range
  @left_contents, @right_contents = [], []
  @consumed_lines = 0
end

Instance Attribute Details

#left_contentsObject (readonly)

Returns the value of attribute left_contents.



57
58
59
# File 'lib/ascii-data-tools/filter/diffing.rb', line 57

def left_contents
  @left_contents
end

#right_contentsObject (readonly)

Returns the value of attribute right_contents.



57
58
59
# File 'lib/ascii-data-tools/filter/diffing.rb', line 57

def right_contents
  @right_contents
end

Instance Method Details

#complete?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/ascii-data-tools/filter/diffing.rb', line 65

def complete?
  @consumed_lines == lines_to_consume
end

#consume(line) ⇒ Object



69
70
71
72
73
74
75
76
77
# File 'lib/ascii-data-tools/filter/diffing.rb', line 69

def consume(line)
  if line =~ /^[<>]/
    case line[0..0]
    when "<" then @left_contents << line[2..-1]
    when ">" then @right_contents << line[2..-1]
    end
  end
  @consumed_lines += 1
end