Class: Undies::IO
- Inherits:
-
Object
- Object
- Undies::IO
- Defined in:
- lib/undies/io.rb
Instance Attribute Summary collapse
-
#indent ⇒ Object
readonly
the IO class wraps a stream (anything that responds to ‘<<’ and gathers streaming options options. handles writing markup to the stream..
-
#level ⇒ Object
Returns the value of attribute level.
-
#newline ⇒ Object
readonly
the IO class wraps a stream (anything that responds to ‘<<’ and gathers streaming options options. handles writing markup to the stream..
-
#node_stack ⇒ Object
readonly
the IO class wraps a stream (anything that responds to ‘<<’ and gathers streaming options options. handles writing markup to the stream..
-
#stream ⇒ Object
readonly
the IO class wraps a stream (anything that responds to ‘<<’ and gathers streaming options options. handles writing markup to the stream..
Instance Method Summary collapse
- #<<(markup) ⇒ Object
- #current ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(stream, opts = {}) ⇒ IO
constructor
A new instance of IO.
- #line_indent(relative_level = 0) ⇒ Object
- #options=(opts) ⇒ Object
- #pop ⇒ Object
- #push(scope) ⇒ Object
- #push!(scope) ⇒ Object
Constructor Details
#initialize(stream, opts = {}) ⇒ IO
Returns a new instance of IO.
11 12 13 14 15 |
# File 'lib/undies/io.rb', line 11 def initialize(stream, opts={}) @stream = stream @node_stack = [] self. = opts end |
Instance Attribute Details
#indent ⇒ Object (readonly)
the IO class wraps a stream (anything that responds to ‘<<’ and gathers streaming options options. handles writing markup to the stream.
8 9 10 |
# File 'lib/undies/io.rb', line 8 def indent @indent end |
#level ⇒ Object
Returns the value of attribute level.
9 10 11 |
# File 'lib/undies/io.rb', line 9 def level @level end |
#newline ⇒ Object (readonly)
the IO class wraps a stream (anything that responds to ‘<<’ and gathers streaming options options. handles writing markup to the stream.
8 9 10 |
# File 'lib/undies/io.rb', line 8 def newline @newline end |
#node_stack ⇒ Object (readonly)
the IO class wraps a stream (anything that responds to ‘<<’ and gathers streaming options options. handles writing markup to the stream.
8 9 10 |
# File 'lib/undies/io.rb', line 8 def node_stack @node_stack end |
#stream ⇒ Object (readonly)
the IO class wraps a stream (anything that responds to ‘<<’ and gathers streaming options options. handles writing markup to the stream.
8 9 10 |
# File 'lib/undies/io.rb', line 8 def stream @stream end |
Instance Method Details
#<<(markup) ⇒ Object
31 32 33 |
# File 'lib/undies/io.rb', line 31 def <<(markup) @stream << markup end |
#current ⇒ Object
38 |
# File 'lib/undies/io.rb', line 38 def current; @node_stack.last; end |
#empty? ⇒ Boolean
39 |
# File 'lib/undies/io.rb', line 39 def empty?; @node_stack.empty? end |
#line_indent(relative_level = 0) ⇒ Object
27 28 29 |
# File 'lib/undies/io.rb', line 27 def line_indent(relative_level=0) "#{' '*(@level+relative_level)*@indent}" end |
#options=(opts) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/undies/io.rb', line 17 def (opts) if !opts.kind_of?(::Hash) raise ArgumentError, "please provide a hash to set IO options" end @indent = opts[:pp] || 0 @newline = opts[:pp].nil? ? "" : "\n" @level = opts[:level] || 0 end |
#pop ⇒ Object
37 |
# File 'lib/undies/io.rb', line 37 def pop; @level -= 1; @node_stack.pop; end |
#push(scope) ⇒ Object
35 |
# File 'lib/undies/io.rb', line 35 def push(scope); @level += 1; push!(scope); end |
#push!(scope) ⇒ Object
36 |
# File 'lib/undies/io.rb', line 36 def push!(scope); @node_stack.push(scope); end |