rg_dishes 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 87ca6a8295f9c40877f37a9b2d2822200b8db2454b937a2519a8e07123afe40a
4
+ data.tar.gz: a92cc754cd3e4ecda86f265ebf68c2042d8680944472508aa82fd8d09bde01fa
5
+ SHA512:
6
+ metadata.gz: e69d52a3233c6d82c92084284d79d965c22315df981a3a957eb206b58fe8db4e25262feca9d9c76774e60c701c078215467155d535f539d5cc854f60befa559d
7
+ data.tar.gz: f44e9be5e1dfc5a904501d5759cdfa082d5d0baee1c6e28956619b066cbc7b8e4b75ea8a4a9ea51876157ad108d0bab0bb7e415abae7ed871b91e1e78413c633
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-03-07
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in rg_dishes.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
11
+
12
+ gem 'minitest-reporters', '1.2.0'
data/Gemfile.lock ADDED
@@ -0,0 +1,30 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rg_dishes (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ansi (1.5.0)
10
+ builder (3.2.4)
11
+ minitest (5.14.4)
12
+ minitest-reporters (1.2.0)
13
+ ansi
14
+ builder
15
+ minitest (>= 5.0)
16
+ ruby-progressbar
17
+ rake (13.0.3)
18
+ ruby-progressbar (1.11.0)
19
+
20
+ PLATFORMS
21
+ x86_64-darwin-19
22
+
23
+ DEPENDENCIES
24
+ minitest (~> 5.0)
25
+ minitest-reporters (= 1.2.0)
26
+ rake (~> 13.0)
27
+ rg_dishes!
28
+
29
+ BUNDLED WITH
30
+ 2.2.13
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # RgDishes
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rg_dishes`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'rg_dishes'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install rg_dishes
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rg_dishes.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "rg_dishes"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/rg_dishes.rb ADDED
@@ -0,0 +1,147 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "rg_dishes/version"
4
+
5
+ require 'csv'
6
+
7
+ module RgDishes
8
+ class Error < StandardError; end
9
+ extend self
10
+
11
+ #takes in dish name and returns its ingredients string.
12
+ def dish_to_ingredients(dish_key, data)
13
+ if data[dish_key.downcase]
14
+ ingredients = data[dish_key.downcase].join(", ")
15
+ else
16
+ ingredients = nil
17
+ end
18
+ ingredients
19
+ end
20
+
21
+ #returns ingredients sentence from dish name and ingredients
22
+ def construct_ingredients_sentence(ingredients, dish_arg)
23
+ if ingredients
24
+ ingredients_sentence = "Ingredients for #{dish_arg}: #{ingredients}."
25
+ else
26
+ ingredients_sentence = "I don't know the ingredients for #{dish_arg}."
27
+ end
28
+ ingredients_sentence
29
+ end
30
+
31
+ #takes in dish_arg, dish_key, returns ingredients sentence
32
+ def dish_to_sentence(dish_arg, dish_key, data)
33
+ ingredients = dish_to_ingredients(dish_key, data)
34
+ sentence = construct_ingredients_sentence(ingredients, dish_arg)
35
+ sentence
36
+ end
37
+
38
+ #returns the names of all dishes in hash
39
+ def list_all_dishes(table)
40
+ dishes = table.keys
41
+ dishes
42
+ end
43
+
44
+ #returns hash{ingredient => number}
45
+ def build_count_hash(ingredients)
46
+ ing_num_hash = {}
47
+ ingredients.each do |ingredient|
48
+ if ing_num_hash[ingredient]
49
+ ing_num_hash[ingredient] += 1
50
+ else
51
+ ing_num_hash[ingredient] = 1
52
+ end
53
+ end
54
+ ing_num_hash
55
+ end
56
+
57
+ #returns array of strings for ingredients with number (where >2 dishes)
58
+ def build_counted_dishes_array(ingredients_num_hash)
59
+ ing_array = []
60
+ ingredients_num_hash.each do |ingr, num|
61
+ if num > 1
62
+ ingr_string = ingr + " (*" + num.to_s + " dishes)"
63
+ else
64
+ ingr_string = ingr
65
+ end
66
+ ing_array << ingr_string
67
+ end
68
+ ing_array
69
+ end
70
+
71
+ #returns shopping list array
72
+ def make_shopping_list(ingr_array, no_ingr_dishes)
73
+ ingredients_string = ingr_array.uniq.sort.join("\n")
74
+ shopping_list = []
75
+ if !ingredients_string.empty?
76
+ shopping_list << ingredients_string
77
+ end
78
+ if !no_ingr_dishes.empty?
79
+ shopping_list << "I don't know the ingredients for #{no_ingr_dishes.join(", ")}."
80
+ end
81
+ shopping_list
82
+ end
83
+
84
+ #----------------
85
+
86
+ #reads csv into array of arrays.
87
+ #doc = CSV.read("dishes.csv")
88
+
89
+ def table_method
90
+ doc = [["carbonara", "spaghetti", "bacon", "egg", "pecorino", nil, nil, nil, nil, nil, nil, nil, nil, nil, nil], ["menemen", "egg", "pepper", "tomato", "bread", nil, nil, nil, nil, nil, nil, nil, nil, nil, nil], ["sausages in a tray", "sausages", "sweet potato", "onion", "apple", "herbs", nil, nil, nil, nil, nil, nil, nil, nil, nil], ["stir fry", "noodles", "stir fry vegetables", "tofu", "fish sauce", "soy sauce", "garlic", "ginger", nil, nil, nil, nil, nil, nil, nil], ["spaghetti alle cozze", "spaghetti", "mussels", "white wine", "garlic", "chili flakes", "parsley", nil, nil, nil, nil, nil, nil, nil, nil], ["risotto", "risotto rice", "white wine", "stock", "herbs", "butter", nil, nil, nil, nil, nil, nil, nil, nil, nil], ["salmon en croute", "salmon", "pastry", "soft cheese", "lemon juice", "dill", "watercress", "egg", nil, nil, nil, nil, nil, nil, nil], ["grilled aubergine", "aubergine", "lemon", "garlic", "oregano", "basil", nil, nil, nil, nil, nil, nil, nil, nil, nil], ["aubergine parmigiana", "aubergine", "shallot", "garlic", "canned tomatoes", "basil", "parmesan", "chili flakes", nil, nil, nil, nil, nil, nil, nil], ["caramelized onion and blue cheese cups", "pastry", "red onion", "cider vinegar", "brown sugar", "blue cheese", "walnuts", "egg", nil, nil, nil, nil, nil, nil, nil], ["tuna steak", "tuna steak", "garlic", "ginger", "soy sauce", "orange juice", "lemon juice", nil, nil, nil, nil, nil, nil, nil, nil], ["roast potatoes", "potatoes", "herbs", nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil], ["roast carrots and parsnips", "carrots", "parsnips", "honey", "thyme", nil, nil, nil, nil, nil, nil, nil, nil, nil, nil], ["Hasselbach potatoes", "potatoes", "lemon", nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil], ["roast chicken with a mustard glaze", "chicken", "garlic", "rosemary", "mustard", nil, nil, nil, nil, nil, nil, nil, nil, nil, nil], ["roast chicken with apple and brandy", "chicken", "garlic", "brandy", "apple juice", "onion", nil, nil, nil, nil, nil, nil, nil, nil, nil], ["baked sardines", "sardines", "garlic", "herbs", nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil], ["Beef Wellington", "fillet steak", "shallot", "chestnut mushrooms", "porcini mushrooms", "butter", "thyme", "white wine", "prosciutto", "pastry", "egg", "bay leaf", "stock", "brandy", "red wine"], ["glazed salmon", "salmon", "brown sugar", nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil], ["pesto", "pine nuts", "garlic", "basil", "parmesan", nil, nil, nil, nil, nil, nil, nil, nil, nil, nil], ["Ratatouille", "aubergine", "pepper", "courgette", "tomato", "onion", "garlic", "basil", "thyme", "lemon", "cumin", nil, nil, nil, nil]]
91
+
92
+ #transforms array of arrays into a hash.
93
+ table = {}
94
+ doc.each do |array|
95
+ table[array.shift] = array.compact
96
+ end
97
+
98
+ #transforms all keys in hash to lower case.
99
+ table.transform_keys!(&:downcase)
100
+ table
101
+ end
102
+
103
+ #----------------
104
+
105
+ #dinner inspire returns all dishes in hash
106
+ def inspire
107
+ table = table_method
108
+ list_all_dishes(table).join("\n")
109
+ end
110
+
111
+ #----------------
112
+
113
+ #dinner combine returns ingredients for all dishes
114
+ def combine(dish_array)
115
+ table = table_method
116
+ if dish_array.nil? or dish_array.empty?
117
+ "Please include a dishy argument."
118
+ else
119
+ ingredients = []
120
+ no_ingredients_dishes = []
121
+ dish_array.each do |dish_element|
122
+ arg_string = dish_element.downcase
123
+ if table[arg_string]
124
+ #concat makes array rather than array of arrays
125
+ ingredients.concat(table[arg_string])
126
+ else
127
+ no_ingredients_dishes << dish_element
128
+ end
129
+ end
130
+
131
+ #builds hash to count ingredients
132
+ ingredients_num_hash = build_count_hash(ingredients)
133
+
134
+ #appends number to repeated ingredients
135
+ ingredients_array = build_counted_dishes_array(ingredients_num_hash)
136
+
137
+ #builds shopping list
138
+ shopping_list = make_shopping_list(ingredients_array, no_ingredients_dishes).join("\n")
139
+
140
+ #returns shopping list_all_dishes
141
+ shopping_list
142
+ end
143
+ end
144
+
145
+ #----------------
146
+
147
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RgDishes
4
+ VERSION = "0.1.0"
5
+ end
data/rg_dishes.gemspec ADDED
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/rg_dishes/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "rg_dishes"
7
+ spec.version = RgDishes::VERSION
8
+ spec.authors = ["Rachel Grewcock"]
9
+ spec.email = ["rebgrewcock@gmail.com"]
10
+
11
+ spec.summary = %q{What's for dinner?}
12
+ spec.description = %q{Suggests meals; compiles ingredients lists.}
13
+ spec.homepage = %q{https://github.com/rebgrewcock/rg_dishes}
14
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
15
+
16
+ spec.metadata["allowed_push_host"] = "https://rubygems.org/"
17
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = "https://github.com/rebgrewcock/rg_dishes.git"
20
+ spec.metadata["changelog_uri"] = "https://github.com/rebgrewcock/rg_dishes/blob/main/CHANGELOG.md"
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ # Uncomment to register a new dependency of your gem
32
+ # spec.add_dependency "example-gem", "~> 1.0"
33
+
34
+ # For more information and examples about making a new gem, checkout our
35
+ # guide at: https://bundler.io/guides/creating_gem.html
36
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rg_dishes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Rachel Grewcock
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-03-07 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Suggests meals; compiles ingredients lists.
14
+ email:
15
+ - rebgrewcock@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - CHANGELOG.md
22
+ - Gemfile
23
+ - Gemfile.lock
24
+ - README.md
25
+ - Rakefile
26
+ - bin/console
27
+ - bin/setup
28
+ - lib/rg_dishes.rb
29
+ - lib/rg_dishes/version.rb
30
+ - rg_dishes.gemspec
31
+ homepage: https://github.com/rebgrewcock/rg_dishes
32
+ licenses: []
33
+ metadata:
34
+ allowed_push_host: https://rubygems.org/
35
+ homepage_uri: https://github.com/rebgrewcock/rg_dishes
36
+ source_code_uri: https://github.com/rebgrewcock/rg_dishes.git
37
+ changelog_uri: https://github.com/rebgrewcock/rg_dishes/blob/main/CHANGELOG.md
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 2.4.0
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubygems_version: 3.2.13
54
+ signing_key:
55
+ specification_version: 4
56
+ summary: What's for dinner?
57
+ test_files: []