Class: Kabuto::Recipe
- Inherits:
-
Object
- Object
- Kabuto::Recipe
- Defined in:
- lib/kabuto/recipe.rb
Instance Attribute Summary collapse
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#nested ⇒ Object
readonly
Returns the value of attribute nested.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
-
#initialize(params = {}, &block) ⇒ Recipe
constructor
A new instance of Recipe.
- #method_missing(name, *args, &block) ⇒ Object
- #nested? ⇒ Boolean
- #process(page, meta = nil) ⇒ Object
Constructor Details
#initialize(params = {}, &block) ⇒ Recipe
Returns a new instance of Recipe.
9 10 11 12 13 14 15 |
# File 'lib/kabuto/recipe.rb', line 9 def initialize params={}, &block @params = Hashie::Mash.new(params) @items = Hashie::Mash.new @nested = false instance_eval(&block) if block_given? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/kabuto/recipe.rb', line 17 def method_missing name, *args, &block if block_given? recipe = Recipe.new recipe.instance_eval(&block) @items[name] = RecipeItem.new(:recipe, recipe) @nested = true else type, value, convert_to = args[0..2] @items[name] = RecipeItem.new(type, value, convert_to) end end |
Instance Attribute Details
#items ⇒ Object (readonly)
Returns the value of attribute items.
7 8 9 |
# File 'lib/kabuto/recipe.rb', line 7 def items @items end |
#nested ⇒ Object (readonly)
Returns the value of attribute nested.
7 8 9 |
# File 'lib/kabuto/recipe.rb', line 7 def nested @nested end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
7 8 9 |
# File 'lib/kabuto/recipe.rb', line 7 def params @params end |
Instance Method Details
#nested? ⇒ Boolean
39 40 41 |
# File 'lib/kabuto/recipe.rb', line 39 def nested? @nested end |
#process(page, meta = nil) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/kabuto/recipe.rb', line 29 def process page, = nil result = Hashie::Mash.new items.each do |name, item| result[name] = item.process(page, ) end result end |