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

the output class wraps an IO stream, gathers pretty printing options, and handles buffering nodes and pretty printing to the stream



12
13
14
15
16
# File 'lib/undies/output.rb', line 12

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

Instance Attribute Details

#ioObject (readonly)

Returns the value of attribute io.



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

def io
  @io
end

#node_bufferObject (readonly)

Returns the value of attribute node_buffer.



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

def node_buffer
  @node_buffer
end

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

#ppObject (readonly)

Returns the value of attribute pp.



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

def pp
  @pp
end

#pp_use_indentObject

Returns the value of attribute pp_use_indent.



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

def pp_use_indent
  @pp_use_indent
end

Instance Method Details

#<<(data) ⇒ Object



40
41
42
# File 'lib/undies/output.rb', line 40

def <<(data)
  @io << (@pp_use_indent ? "#{@pp_indent}#{data}" : data.to_s)
end

#flushObject



49
50
51
# File 'lib/undies/output.rb', line 49

def flush
  self.node_buffer.flush(self)
end

#node(obj) ⇒ Object



44
45
46
47
# File 'lib/undies/output.rb', line 44

def node(obj)
  self.node_buffer.pull(self)
  self.node_buffer.push(obj)
end

#pp_levelObject



31
32
33
# File 'lib/undies/output.rb', line 31

def pp_level
  @pp_level
end

#pp_level=(value) ⇒ Object



35
36
37
38
# File 'lib/undies/output.rb', line 35

def pp_level=(value)
  @pp_indent = @pp ? "\n#{' '*value*@pp}" : ""
  @pp_level  = value
end