nutrition_facts 0.4.0 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d2fd795fe24a8d91111cb9f3a0148f4843e50f26
4
- data.tar.gz: 063e7e304585cb5f0077feb898d1b736ee022b6a
3
+ metadata.gz: 4aa2734c02d825a5400343a7de98515abfdd1c8d
4
+ data.tar.gz: 8abe034ba8902df7dec38e4d07e23fe3d834d9e2
5
5
  SHA512:
6
- metadata.gz: c5b2492afca572de047fc8f471bedb5859956108c3401cbdb5fabb950fc2aaa8af7ea1d001595a9d174a376aa15b44463aff6cfb5a0f1e60966f74c01caf5c6a
7
- data.tar.gz: d58d398a93962a038a02b48b161b910e7909118802c54d92d17eeb59677cc53f6ee70088f2f051ac2efa6e67955c71f69ce1395d1a91a9fe5f5702954300a925
6
+ metadata.gz: 20f94b08bc9ad317d8fb06e518e9452e625bf9722d4a770c7aede9e46bef4c4300e6ef3773c2f10ecf8c671aa865238d50c72a86af60c6e998265c8afcaa1eb7
7
+ data.tar.gz: a50881a67b0c3ee3798482eac538f8ab665c2cf0cfc7cda1446e4d489901c748af799485eec005ffed7b6d91e795e03a99f3440ead4772bc974140315aaea498
@@ -17,14 +17,13 @@ class NutritionFacts::CLI
17
17
  get_food_data(food_name)
18
18
 
19
19
  if food_name == 'exit'
20
- puts ''
21
20
  puts 'Thanks for using NutritionFacts CLI!'
22
21
  puts ''
23
22
  elsif !@food_data.nil?
24
23
  which_item
25
24
  else
26
25
  puts 'That item was not found, please try another search term.'
27
- puts ' '
26
+ puts ''
28
27
  NutritionFacts::Item.reset
29
28
  food_search
30
29
  end
@@ -36,21 +35,22 @@ class NutritionFacts::CLI
36
35
 
37
36
  def which_item
38
37
  puts ''
39
- puts "1. #{@food_data[0].item_name}"
40
- puts "2. #{@food_data[1].item_name}"
41
- puts "3. #{@food_data[2].item_name}"
42
- puts ''
38
+ @food_data.each.with_index do |_data, index|
39
+ puts "#{index + 1}. #{@food_data[index].item_name}"
40
+ end
43
41
 
44
42
  user_input = nil
45
43
 
46
44
  loop do
47
- 'Please enter 1, 2, or 3, to see more info about that food:'
45
+ puts ''
46
+ puts 'Please enter the number of the food to see more info about that item:'
48
47
  user_input = gets.chomp
49
- break if user_input == '1' || user_input == '2' || user_input == '3'
50
- puts 'Not sure what you meant, please type 1, 2, or 3.'
48
+ break if user_input.to_i.between?(0, 10)
49
+ puts ''
50
+ puts 'Not sure what you meant, please type the number of the food item.'
51
51
  end
52
52
 
53
- if user_input == '1' || '2' || '3'
53
+ if user_input.to_i.between?(0, 10)
54
54
  display_item(@food_data[user_input.to_i - 1])
55
55
  else
56
56
  loop_or_quit
@@ -76,6 +76,7 @@ class NutritionFacts::CLI
76
76
  def loop_or_quit
77
77
  puts ''
78
78
  puts 'Please type "other", "search", or "exit".'
79
+ puts ''
79
80
  choice = gets.chomp.downcase
80
81
 
81
82
  case choice
@@ -15,7 +15,7 @@ class NutritionFacts::Item
15
15
  end
16
16
 
17
17
  def self.find_by_name(name)
18
- uri = URI.parse("https://api.nutritionix.com/v1_1/search/#{name}?results=0%3A3&cal_min=0&cal_max=50000&fields=item_name%2Cnf_calories%2Cnf_total_fat%2Cnf_total_carbohydrate%2Cnf_dietary_fiber%2Cnf_sugars%2Cnf_protein%2Cnf_serving_weight_grams%2Cnf_sodium%2Cnf_vitamin_a_dv%2Cnf_vitamin_c_dv&appId=da276553&appKey=f501b79647768ba684af20428a44ef59")
18
+ uri = URI.parse("https://api.nutritionix.com/v1_1/search/#{name}?results=0%3A10&cal_min=0&cal_max=50000&fields=item_name%2Cnf_calories%2Cnf_total_fat%2Cnf_total_carbohydrate%2Cnf_dietary_fiber%2Cnf_sugars%2Cnf_protein%2Cnf_serving_weight_grams%2Cnf_sodium%2Cnf_vitamin_a_dv%2Cnf_vitamin_c_dv&appId=da276553&appKey=f501b79647768ba684af20428a44ef59")
19
19
 
20
20
  response = Net::HTTP.get_response(uri)
21
21
 
@@ -24,10 +24,14 @@ class NutritionFacts::Item
24
24
  if raw_data['hits'].empty?
25
25
  puts ''
26
26
  else
27
- @@all << NutritionFacts::Item.new(raw_data['hits'][0]['fields'])
28
- @@all << NutritionFacts::Item.new(raw_data['hits'][1]['fields'])
29
- @@all << NutritionFacts::Item.new(raw_data['hits'][2]['fields'])
27
+ i = 0
28
+ num = raw_data['hits'].count
29
+ while i < num
30
+ @@all << NutritionFacts::Item.new(raw_data['hits'][i]['fields'])
31
+ i += 1
32
+ end
30
33
  end
34
+ @@all
31
35
  end
32
36
 
33
37
  def self.all
@@ -1,3 +1,3 @@
1
1
  module NutritionFacts
2
- VERSION = '0.4.0'.freeze
2
+ VERSION = '0.5.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nutrition_facts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Preiser