class FlameChannelParser::Builder
A Builder-like class for exporting Flame setups
Constants
- INDENT
Public Class Methods
new(io, indent = 0)
click to toggle source
# File lib/builder.rb, line 5 def initialize(io, indent = 0) @io, @indent = io, indent end
Public Instance Methods
<<(some_verbatim_string)
click to toggle source
Append the text passed to the setup. The appended lines will be prepended by the indent of the current builder
# File lib/builder.rb, line 49 def <<(some_verbatim_string) some_verbatim_string.split("\n").each do | line | @io.puts(["\t" * @indent, line].join) end end
color_hash!(name, red, green, blue)
click to toggle source
Write a color hash with the right order of values
# File lib/builder.rb, line 39 def color_hash!(name, red, green, blue) write_unterminated_block!(name) do | b | b.red(red) b.green(green) b.blue(blue) end end
linebreak!(how_many = 1)
click to toggle source
Write a number of linebreaks
# File lib/builder.rb, line 34 def linebreak!(how_many = 1) @io.write("\n" * how_many) end
write_block!(name, value = nil) { |class.new(io, indent + 1)| ... }
click to toggle source
Writes a block of values delimited by “End” terminators. Will yield a nested Builder
objectg which
# File lib/builder.rb, line 11 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
write_loose!(value)
click to toggle source
Write a number of linebreaks
# File lib/builder.rb, line 29 def write_loose!(value) @io.puts("%s%s" % [INDENT * @indent, __camelize(value)]) end
write_tuple!(key, value)
click to toggle source
Write a tuple of “Parameter Value”, like “Frame 13”
# File lib/builder.rb, line 24 def write_tuple!(key, value) @io.puts("%s%s %s" % [INDENT * @indent, __camelize(key), __flameize(value)]) end
write_unterminated_block!(name, value = nil) { |class.new(io, indent + 1)| ... }
click to toggle source
Write an unterminated block of values
# File lib/builder.rb, line 18 def write_unterminated_block!(name, value = nil, &blk) value.nil? ? write_loose!(name) : write_tuple!(name, value) yield(self.class.new(@io, @indent + 1)) end
Private Instance Methods
__camelize(s)
click to toggle source
# File lib/builder.rb, line 69 def __camelize(s) @@camelizations ||= {} @@camelizations[s] ||= s.to_s.gsub(/(^|_)(.)/) { $2.upcase } end
__flameize(v)
click to toggle source
# File lib/builder.rb, line 74 def __flameize(v) case v when Float "%.3f" % v when TrueClass "yes" when FalseClass "no" else v.to_s end end
method_missing(meth, arg = nil) { |c| ... }
click to toggle source
# File lib/builder.rb, line 57 def method_missing(meth, arg = nil) if block_given? write_block!(meth, arg) {|c| yield(c) } else if arg.nil? write_loose!(meth) else write_tuple!(meth, arg) end end end