class Contraption::Formatter
Public Class Methods
new(location)
click to toggle source
# File lib/contraption/formatter.rb, line 5 def initialize location @source = location find_formats end
Public Instance Methods
format(context, method=nil)
click to toggle source
# File lib/contraption/formatter.rb, line 10 def format context, method=nil renderer(method || context.type).result binding end
formats()
click to toggle source
# File lib/contraption/formatter.rb, line 14 def formats @formats.keys end
Private Instance Methods
find_formats()
click to toggle source
# File lib/contraption/formatter.rb, line 19 def find_formats @formats = @source.list('.erb') .inject({}){|collection, f| collection[f.split('.').first.to_sym] = f; collection} end
renderer(type)
click to toggle source
# File lib/contraption/formatter.rb, line 24 def renderer type ERB.new @source.read( @formats.fetch(type){ raise ArgumentError, "#{type} is not a valid format" } ) end