Class: Undies::Output

Inherits:
Object
  • Object
show all
Defined in:
lib/undies/output.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io, opts = {}) ⇒ Output



10
11
12
13
# File 'lib/undies/output.rb', line 10

def initialize(io, opts={})
  @io = io
  self.options = opts
end

Instance Attribute Details

#ioObject (readonly)

the output class wraps an IO stream, gathers pretty printing options, and handles writing out buffered node stack items



7
8
9
# File 'lib/undies/output.rb', line 7

def io
  @io
end

#ppObject (readonly)

the output class wraps an IO stream, gathers pretty printing options, and handles writing out buffered node stack items



7
8
9
# File 'lib/undies/output.rb', line 7

def pp
  @pp
end

#pp_levelObject

Returns the value of attribute pp_level.



8
9
10
# File 'lib/undies/output.rb', line 8

def pp_level
  @pp_level
end

Instance Method Details

#options=(opts) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/undies/output.rb', line 15

def options=(opts)
  if !opts.kind_of?(::Hash)
    raise ArgumentError, "please provide a hash to set options with"
  end

  # setup any pretty printing
  @pp = opts[:pp] || 0
  @pp_level = opts[:pp_level] || 0
end

#write(node, meth, level) ⇒ Object



25
26
27
28
# File 'lib/undies/output.rb', line 25

def write(node, meth, level)
  @io << node.class.prefix(node, meth, level+@pp_level, @pp)
  @io << node.class.send(meth, node)
end