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 = "") ⇒ Object

Returns out.

Returns:

  • out



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

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

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

  recurse(@zipper.node, @separators, out)
  return out
end