lib/undies/output.rb in undies-2.2.0 vs lib/undies/output.rb in undies-2.2.1

- old
+ new

@@ -1,54 +1,31 @@ -require 'undies/node_buffer' - module Undies class Output - attr_reader :io, :options, :pp, :node_buffer - attr_accessor :pp_use_indent - # the output class wraps an IO stream, gathers pretty printing options, - # and handles buffering nodes and pretty printing to the stream + # and handles writing out buffered node stack items + attr_reader :io, :pp + attr_accessor :pp_level + def initialize(io, opts={}) @io = io self.options = opts - @node_buffer = NodeBuffer.new end 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] - self.pp_level = opts[:pp_level] || 0 - self.pp_use_indent = true - - @options = opts + @pp = opts[:pp] || 0 + @pp_level = opts[:pp_level] || 0 end - def pp_level - @pp_level - end - - def pp_level=(value) - @pp_indent = @pp ? "\n#{' '*value*@pp}" : "" - @pp_level = value - end - - def <<(data) - @io << (@pp_use_indent ? "#{@pp_indent}#{data}" : data.to_s) - end - - def node(obj) - self.node_buffer.pull(self) - self.node_buffer.push(obj) - end - - def flush - self.node_buffer.flush(self) + def write(node, meth, level) + @io << node.class.prefix(node, meth, level+@pp_level, @pp) + @io << node.class.send(meth, node) end end end