class Undies::IO

Attributes

indent[R]

the IO class wraps a stream (anything that responds to '<<' and gathers streaming options options. handles writing markup to the stream.

level[RW]
newline[R]

the IO class wraps a stream (anything that responds to '<<' and gathers streaming options options. handles writing markup to the stream.

node_stack[R]

the IO class wraps a stream (anything that responds to '<<' and gathers streaming options options. handles writing markup to the stream.

stream[R]

the IO class wraps a stream (anything that responds to '<<' and gathers streaming options options. handles writing markup to the stream.

Public Class Methods

new(stream, opts={}) click to toggle source
# File lib/undies/io.rb, line 11
def initialize(stream, opts={})
  @stream = stream
  @node_stack = []
  self.options = opts
end

Public Instance Methods

<<(markup) click to toggle source
# File lib/undies/io.rb, line 31
def <<(markup)
  @stream << markup
end
current() click to toggle source
# File lib/undies/io.rb, line 38
def current; @node_stack.last; end
empty?() click to toggle source
# File lib/undies/io.rb, line 39
def empty?; @node_stack.empty? end
line_indent(relative_level=0) click to toggle source
# File lib/undies/io.rb, line 27
def line_indent(relative_level=0)
  "#{' '*(@level+relative_level)*@indent}"
end
options=(opts) click to toggle source
# File lib/undies/io.rb, line 17
def options=(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() click to toggle source
# File lib/undies/io.rb, line 37
def pop; @level -= 1; @node_stack.pop; end
push(scope) click to toggle source
# File lib/undies/io.rb, line 35
def push(scope); @level += 1; push!(scope); end
push!(scope) click to toggle source
# File lib/undies/io.rb, line 36
def push!(scope); @node_stack.push(scope); end