Class: Kabutops::Recipe
- Inherits:
-
Object
- Object
- Kabutops::Recipe
- Defined in:
- lib/kabutops/recipe.rb
Instance Attribute Summary collapse
-
#items ⇒ Object
readonly
Returns the value of attribute items.
Instance Method Summary collapse
-
#initialize ⇒ Recipe
constructor
A new instance of Recipe.
- #method_missing(name, *args, &block) ⇒ Object
- #nested? ⇒ Boolean
- #process(resource, page) ⇒ Object
Constructor Details
#initialize ⇒ Recipe
Returns a new instance of Recipe.
8 9 10 11 |
# File 'lib/kabutops/recipe.rb', line 8 def initialize @items = Hashie::Mash.new @nested = false end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/kabutops/recipe.rb', line 13 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 = args[0..1] @items[name] = RecipeItem.new(type, value) end end |
Instance Attribute Details
#items ⇒ Object (readonly)
Returns the value of attribute items.
6 7 8 |
# File 'lib/kabutops/recipe.rb', line 6 def items @items end |
Instance Method Details
#nested? ⇒ Boolean
35 36 37 |
# File 'lib/kabutops/recipe.rb', line 35 def nested? @nested end |
#process(resource, page) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/kabutops/recipe.rb', line 25 def process resource, page result = Hashie::Mash.new @items.each do |name, item| result[name] = item.process(resource, page) end result end |