class BeerRecipe::RecipeFormatter
Public Class Methods
new(options = {})
click to toggle source
# File lib/beer_recipe/recipe_formatter.rb, line 2 def initialize(options = {}) @options = options end
Public Instance Methods
format(recipe)
click to toggle source
# File lib/beer_recipe/recipe_formatter.rb, line 6 def format(recipe) @recipe = recipe self end
format_records(records, set)
click to toggle source
# File lib/beer_recipe/recipe_formatter.rb, line 36 def format_records(records, set) if records.size > 0 send("before_#{set}") if respond_to? "before_#{set}" records.each do |record| if respond_to? record.format_method send(record.format_method, record) end end send("after_#{set}") if respond_to? "after_#{set}" end end
output()
click to toggle source
# File lib/beer_recipe/recipe_formatter.rb, line 28 def output format_recipe BeerRecipe::RecipeWrapper::SETS.map do |set| format_records(@recipe.send(set), set) end format_mash(@recipe.mash) end
parse()
click to toggle source
# File lib/beer_recipe/recipe_formatter.rb, line 23 def parse erb = ERB.new(template).result(@recipe.get_binding) StringIO.new(erb) end
template()
click to toggle source
# File lib/beer_recipe/recipe_formatter.rb, line 19 def template IO.read(template_file) end
template_file()
click to toggle source
# File lib/beer_recipe/recipe_formatter.rb, line 15 def template_file raise BeerRecipe::NotImplementedError.new end
template_path(file)
click to toggle source
# File lib/beer_recipe/recipe_formatter.rb, line 11 def template_path(file) Pathname.new(File.join(File.dirname(__FILE__), '..', '..', 'template', file)).realpath end