Class: Brewser::Recipe

Inherits:
Model
  • Object
show all
Defined in:
lib/brewser/model/recipe.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#as_beerxml, #as_brewson, auto_migrate_down!, auto_migrate_up!, auto_upgrade!, default_repository_name

Class Method Details

.json_create(o) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/brewser/model/recipe.rb', line 72

def self.json_create(o)
  a = self.new
  a.name = o['name']
  a.description = o['description']
  a.brewer = o['brewer']
  a.method = o['method']
  a.type = o['type']
  a.style = o['style']
  a.mash_schedule = o['mash_schedule']
  a.fermentation_schedule = o['fermentation_schedule']
  a.water_profile = o['water_profile']
  o['fermentables'].each do |fermentable|
    a.fermentables.push fermentable
  end unless o['fermentables'].nil?
  o['hops'].each do |hop|
    a.hops.push hop
  end unless o['hops'].nil?
  o['additives'].each do |additive|
    a.additives.push additive
  end unless o['additives'].nil?
  o['yeasts'].each do |yeast|
    a.yeasts.push yeast
  end unless o['yeasts'].nil?
  a.recipe_volume = o['recipe_volume'].u unless o['recipe_volume'].blank?
  a.boil_volume = o['boil_volume'].u unless o['boil_volume'].blank?
  a.boil_time = o['boil_time'].u unless o['boil_time'].blank?
  a.recipe_efficiency = o['recipe_efficiency']
  a.estimated_og = o['estimated_og']
  a.estimated_fg = o['estimated_fg']
  a.estimated_color = o['estimated_color']
  a.estimated_ibu = o['estimated_ibu']
  a.estimated_abv = o['estimated_abv']
  a.carbonation_level = o['carbonation_level']
  a.source = o['source']
  a.url = o['url']

  return a
end

Instance Method Details

#as_json(options = {}) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/brewser/model/recipe.rb', line 48

def as_json(options={})
  {
    JSON.create_id => "Brewser::Recipe",
    'name' => name, 
    'description' => description, 
    'type' => type,
    'method' => method,
    'brewer' => brewer,
    'style' => style,
    'recipe_volume' => recipe_volume.to_s, 
    'boil_volume' => boil_volume.to_s,
    'boil_time' => boil_time.to_s, 
    'recipe_efficiency' => recipe_efficiency, 
    'hops' => hops.to_a, 'fermentables' => fermentables.to_a, 
    'additives' => additives.to_a, 'yeasts' => yeasts.to_a,
    'mash_schedule' => mash_schedule, 'fermentation_schedule' => fermentation_schedule, 
    'water_profile' => water_profile,
    'estimated_og' => estimated_og, 'estimated_fg' => estimated_fg, 
    'estimated_color' => estimated_color, 'estimated_ibu' => estimated_ibu, 
    'estimated_abv' => estimated_abv, 'carbonation_level' => carbonation_level, 
    'source' => source, 'url' => url
  }
end