Sha256: c36b9756e6c1306479963dc9e28050976173d011c80027b704e0a7ce59532c97
Contents?: true
Size: 1.24 KB
Versions: 1
Compression:
Stored size: 1.24 KB
Contents
# A Builder-like class for exporting Flame setups class Tracksperanto::FlameBuilder INDENT = "\t" def initialize(io, indent = 0) @io, @indent = io, indent end def write_block(name, value = nil, &blk) value.nil? ? write_loose(name) : write_tuple(name, value) yield(self.class.new(@io, @indent + 1)) @io.puts(INDENT * (@indent + 1) + "End") end def write_tuple(key, value) @io.puts("%s%s %s" % [INDENT * @indent, camelize(key), flameize(value)]) end def write_loose(value) @io.puts("%s%s" % [INDENT * @indent, camelize(value)]) end def linebreak!(how_many = 1) @io.write("\n" * how_many) end def color_hash!(name, red, green, blue) write_loose(name) n = self.class.new(@io, @indent + 1) n.red(red) n.green(green) n.blue(blue) end private def method_missing(meth, arg = nil) if block_given? write_block(meth, arg) { |c| yield(c) } else arg.nil? ? write_loose(meth) : write_tuple(meth, arg) end end def camelize(s) s.to_s.gsub(/(^|_)(.)/) { $2.upcase } end def flameize(v) case v when Float "%.3f" % v when TrueClass "yes" when FalseClass "no" else v.to_s end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
tracksperanto-1.8.0 | lib/tracksperanto/flame_builder.rb |