Class: Stupidedi::Writer::Default

Inherits:
Object
  • Object
show all
Defined in:
lib/stupidedi/writer/default.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(zipper, separators = Reader::Separators.empty) ⇒ Default

Returns a new instance of Default.



9
10
11
12
# File 'lib/stupidedi/writer/default.rb', line 9

def initialize(zipper, separators = Reader::Separators.empty)
  @zipper, @separators =
    zipper, separators
end

Instance Attribute Details

#separatorsReader::Separators (readonly)

Returns:



7
8
9
# File 'lib/stupidedi/writer/default.rb', line 7

def separators
  @separators
end

Instance Method Details

#write(out = "")

Returns out.

Returns:

  • out



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/stupidedi/writer/default.rb', line 15

def write(out = "")
  unless @zipper.node.transmission? or @zipper.node.interchange?
    common  = @separators.characters & @zipper.node.characters
    message = common.to_a.map(&:inspect).join(", ")

    if common.present?
      raise Exceptions::OutputError,
        "separator characters #{message} occur as data"
    end
  end

  out.tap { recurse(@zipper.node, @separators, out) }
end