Class: Brewscribe::IngredientList

Inherits:
Object
  • Object
show all
Defined in:
lib/brewscribe/ingredient_list.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeIngredientList

Returns a new instance of IngredientList.



40
41
42
43
44
# File 'lib/brewscribe/ingredient_list.rb', line 40

def initialize
  @grains = []
  @hops   = []
  @yeasts  = []
end

Instance Attribute Details

#grainsObject (readonly)

Returns the value of attribute grains.



7
8
9
# File 'lib/brewscribe/ingredient_list.rb', line 7

def grains
  @grains
end

#hopsObject (readonly)

Returns the value of attribute hops.



7
8
9
# File 'lib/brewscribe/ingredient_list.rb', line 7

def hops
  @hops
end

#yeastsObject (readonly)

Returns the value of attribute yeasts.



7
8
9
# File 'lib/brewscribe/ingredient_list.rb', line 7

def yeasts
  @yeasts
end

Class Method Details

.from_data(data) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/brewscribe/ingredient_list.rb', line 8

def self.from_data data
  list = new

  case data[:grain]
  when Array
    data[:grain].each do |grain|
      list.add_grain grain
    end
  when Hash
    list.add_grain data[:grain]
  end

  case data[:hops]
  when Array
    data[:hops].each do |hops|
      list.add_hops hops
    end
  when Hash
    list.add_hops data[:hops]
  end

  case data[:yeast]
  when Array
    data[:yeast].each do |yeast|
      list.add_yeast yeast
    end
  when Hash
    list.add_yeast data[:yeast]
  end
  list
end

Instance Method Details

#add_grain(grain_data) ⇒ Object



46
47
48
# File 'lib/brewscribe/ingredient_list.rb', line 46

def add_grain grain_data
  @grains << Grain.new(grain_data)
end

#add_hops(hop_data) ⇒ Object



50
51
52
# File 'lib/brewscribe/ingredient_list.rb', line 50

def add_hops hop_data
  @hops << Hops.new(hop_data)
end

#add_yeast(yeast_data) ⇒ Object



54
55
56
# File 'lib/brewscribe/ingredient_list.rb', line 54

def add_yeast yeast_data
  @yeasts << Yeast.new(yeast_data) 
end