Class: AsciiDataTools::Filter::Diffing::DiffFormattingFilter

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

Constant Summary collapse

DIFF_DELIMITER =
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n"

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from FormattingFilter

#filter

Methods inherited from Filter

#<<, #has_records?, #read

Constructor Details

#initialize(type_determiner) ⇒ DiffFormattingFilter

Returns a new instance of DiffFormattingFilter.



9
10
11
12
13
14
# File 'lib/ascii-data-tools/filter/diffing.rb', line 9

def initialize(type_determiner)
  super(nil, type_determiner)
  def @formatter.formattable(record_type)
    record_type.extend(Formatting::UnnumberedFormatableType) unless record_type.instance_of?(Formatting::UnnumberedFormatableType)
  end
end

Class Method Details

.formattable(record_type) ⇒ Object



11
12
13
# File 'lib/ascii-data-tools/filter/diffing.rb', line 11

def @formatter.formattable(record_type)
  record_type.extend(Formatting::UnnumberedFormatableType) unless record_type.instance_of?(Formatting::UnnumberedFormatableType)
end

Instance Method Details

#write(*streams) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ascii-data-tools/filter/diffing.rb', line 16

def write(*streams)
  while upstream.has_records?
    difference = upstream.read
    difference.left_contents.each {|rec| streams[0] << filter(rec)}
    difference.right_contents.each {|rec| streams[1] << filter(rec)}
    if upstream.has_records?
      streams[0] << DIFF_DELIMITER
      streams[1] << DIFF_DELIMITER
    end
  end
end