Class: Kabuto::Recipe

Inherits:
Object
  • Object
show all
Defined in:
lib/kabuto/recipe.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#itemsObject (readonly)

Returns the value of attribute items.



7
8
9
# File 'lib/kabuto/recipe.rb', line 7

def items
  @items
end

#nestedObject (readonly)

Returns the value of attribute nested.



7
8
9
# File 'lib/kabuto/recipe.rb', line 7

def nested
  @nested
end

#paramsObject (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

Returns:

  • (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, meta = nil
  result = Hashie::Mash.new

  items.each do |name, item|
    result[name] = item.process(page, meta)
  end

  result
end