Class: Homecooking::Systems::Kitchen
- Inherits:
-
Object
- Object
- Homecooking::Systems::Kitchen
- Defined in:
- lib/homecooking/systems/kitchen.rb
Instance Method Summary collapse
-
#initialize(opts) ⇒ Kitchen
constructor
A new instance of Kitchen.
- #menu ⇒ Object
- #shopping_list(*recipes) ⇒ Object
Constructor Details
#initialize(opts) ⇒ Kitchen
Returns a new instance of Kitchen.
9 10 11 12 13 |
# File 'lib/homecooking/systems/kitchen.rb', line 9 def initialize(opts) @terminal = opts[:terminal] @dir = Boundaries::Dir.new(scope: opts[:recipes_dir]) @logic = Logic.new end |
Instance Method Details
#menu ⇒ Object
15 16 17 18 |
# File 'lib/homecooking/systems/kitchen.rb', line 15 def @terminal.puts @dir.glob('*.recipe*').map{|filename| File.basename(filename).split('.').first }.join(', ') end |
#shopping_list(*recipes) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/homecooking/systems/kitchen.rb', line 20 def shopping_list(*recipes) recipes_ds = @dir.glob("*.recipe.json").map do |file| [File.basename(file).split('.').first, JSON.parse(IO.read(file))] end.to_h more_recipes = @dir.glob("*.recipe").map do |file| [File.basename(file).split('.').first, @logic.dot_recipe(IO.read(file))] end.to_h ingredients = JSON.parse(@dir.read('ingredients')) @terminal.puts @logic.shopping_list(recipes_ds.merge(more_recipes), ingredients, recipes) end |