Class: Undies::Output
- Inherits:
-
Object
- Object
- Undies::Output
- Defined in:
- lib/undies/output.rb
Instance Attribute Summary collapse
-
#io ⇒ Object
readonly
Returns the value of attribute io.
-
#node_buffer ⇒ Object
readonly
Returns the value of attribute node_buffer.
-
#options ⇒ Object
Returns the value of attribute options.
-
#pp ⇒ Object
readonly
Returns the value of attribute pp.
-
#pp_use_indent ⇒ Object
Returns the value of attribute pp_use_indent.
Instance Method Summary collapse
- #<<(data) ⇒ Object
- #flush ⇒ Object
-
#initialize(io, opts = {}) ⇒ Output
constructor
the output class wraps an IO stream, gathers pretty printing options, and handles buffering nodes and pretty printing to the stream.
- #node(obj) ⇒ Object
- #pp_level ⇒ Object
- #pp_level=(value) ⇒ Object
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. = opts @node_buffer = NodeBuffer.new end |
Instance Attribute Details
#io ⇒ Object (readonly)
Returns the value of attribute io.
6 7 8 |
# File 'lib/undies/output.rb', line 6 def io @io end |
#node_buffer ⇒ Object (readonly)
Returns the value of attribute node_buffer.
6 7 8 |
# File 'lib/undies/output.rb', line 6 def node_buffer @node_buffer end |
#options ⇒ Object
Returns the value of attribute options.
6 7 8 |
# File 'lib/undies/output.rb', line 6 def @options end |
#pp ⇒ Object (readonly)
Returns the value of attribute pp.
6 7 8 |
# File 'lib/undies/output.rb', line 6 def pp @pp end |
#pp_use_indent ⇒ Object
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 |
#flush ⇒ Object
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_level ⇒ Object
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 |