Class: Brewscribe::IngredientList
- Inherits:
-
Object
- Object
- Brewscribe::IngredientList
- Defined in:
- lib/brewscribe/ingredient_list.rb
Instance Attribute Summary collapse
-
#grains ⇒ Object
readonly
Returns the value of attribute grains.
-
#hops ⇒ Object
readonly
Returns the value of attribute hops.
-
#yeasts ⇒ Object
readonly
Returns the value of attribute yeasts.
Class Method Summary collapse
Instance Method Summary collapse
- #add_grain(grain_data) ⇒ Object
- #add_hops(hop_data) ⇒ Object
- #add_yeast(yeast_data) ⇒ Object
-
#initialize ⇒ IngredientList
constructor
A new instance of IngredientList.
Constructor Details
#initialize ⇒ IngredientList
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
#grains ⇒ Object (readonly)
Returns the value of attribute grains.
7 8 9 |
# File 'lib/brewscribe/ingredient_list.rb', line 7 def grains @grains end |
#hops ⇒ Object (readonly)
Returns the value of attribute hops.
7 8 9 |
# File 'lib/brewscribe/ingredient_list.rb', line 7 def hops @hops end |
#yeasts ⇒ Object (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 |