class Erlash::Formatter

Attributes

objs[R]
options[R]
output[R]
registry[R]

Public Class Methods

format(inst, obj) click to toggle source

def self.call(inst, obj)

registry = inst.registry
formatter = registry.find(obj.class)
if formatter
  formatter.call(inst, obj)
elsif obj.respond_to?(:to_erlash)
  obj.to_erlash
else
  obj.to_s
end

end

# File lib/erlash/formatter.rb, line 15
def self.format(inst, obj)
  registry = inst.registry
  formatter = registry.find(obj.class)
  if formatter
    formatter.format(inst, obj)
  else
    obj.to_s
  end
end
new(registry, options = {}) click to toggle source
# File lib/erlash/formatter.rb, line 26
def initialize(registry, options = {})
  @registry = registry
  @output = StringIO.new
  @objs = []
  @options = options
end

Public Instance Methods

<<(elem) click to toggle source
# File lib/erlash/formatter.rb, line 33
def <<(elem)
  objs << elem
end
string()
Alias for: to_s
to_s() click to toggle source
# File lib/erlash/formatter.rb, line 37
def to_s
  return @to_s if defined?(@to_s)
  objs.each do |e|
    output.puts format_elem(e)
  end
  @to_s = output.string
end
Also aliased as: string

Private Instance Methods

format_elem(elem) click to toggle source
# File lib/erlash/formatter.rb, line 48
def format_elem(elem)
  self.class.format(self, elem)
end