Class: Mg2en::Ingredient

Inherits:
Object
  • Object
show all
Defined in:
lib/mg2en/ingredient.rb

Overview

This class holds an ingredient.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(i) ⇒ Ingredient

Returns a new instance of Ingredient.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/mg2en/ingredient.rb', line 9

def initialize(i)
  if i.key?('DESCRIPTION')
    @group       = false
    @quantity    = i['QUANTITY']
    @measurement = i['MEASUREMENT']
    @description = i['DESCRIPTION']
    @direction   = i['DIRECTION']
    @link        = i['INCLUDED_RECIPE_ID'] > 0
  elsif i.key?('DIVIDER_INGREDIENT')
    @group       = true
    @description = i['DIVIDER_INGREDIENT']['DESCRIPTION']
    @ingredients = []
    ingts = i['INGREDIENTS']
    ingts.each do |ing|
      ingredient = Mg2en::Ingredient.new(ing)
      @ingredients.push ingredient
    end
  else
    fail 'Did not recognize input'
  end
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



4
5
6
# File 'lib/mg2en/ingredient.rb', line 4

def description
  @description
end

#directionObject (readonly)

Returns the value of attribute direction.



4
5
6
# File 'lib/mg2en/ingredient.rb', line 4

def direction
  @direction
end

#groupObject (readonly) Also known as: group?

Returns the value of attribute group.



4
5
6
# File 'lib/mg2en/ingredient.rb', line 4

def group
  @group
end

#ingredientsObject (readonly)

Returns the value of attribute ingredients.



4
5
6
# File 'lib/mg2en/ingredient.rb', line 4

def ingredients
  @ingredients
end

Returns the value of attribute link.



4
5
6
# File 'lib/mg2en/ingredient.rb', line 4

def link
  @link
end

#measurementObject (readonly)

Returns the value of attribute measurement.



4
5
6
# File 'lib/mg2en/ingredient.rb', line 4

def measurement
  @measurement
end

#quantityObject (readonly)

Returns the value of attribute quantity.



4
5
6
# File 'lib/mg2en/ingredient.rb', line 4

def quantity
  @quantity
end

Instance Method Details

#to_sObject



31
32
33
34
35
36
# File 'lib/mg2en/ingredient.rb', line 31

def to_s
  return @description if self.group?
  output = ''
  output << @quantity unless @quantity.empty?
  output << without_quantity
end

#without_quantityObject



38
39
40
41
42
43
44
# File 'lib/mg2en/ingredient.rb', line 38

def without_quantity
  output = ''
  output << ' ' << @measurement unless @measurement.empty?
  output << ' ' << @description
  output << ', ' << @direction unless @direction.empty?
  output
end