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.



11
12
13
14
# File 'lib/stupidedi/writer/default.rb', line 11

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

Instance Attribute Details

#separatorsReader::Separators (readonly)

Returns:



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

def separators
  @separators
end

Instance Method Details

#writeObject

Returns out.

Returns:

  • out



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

def write
  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
  out = ""
  recurse(@zipper.node, @separators, out)
  return out
end