fruit-info 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3db4d292fc62ea1974dc4901cd7aa1e38bb4860566d2dc3a62d2eb0d929ffa24
4
- data.tar.gz: 34be9484bb85a3c65ae7ed8139d2ccecafb237e67b3d3efd84e6fe47c0f40161
3
+ metadata.gz: 242c602ab47c169cab13bc0c2c0e312bbd425544707cecf7cab29183b51c5063
4
+ data.tar.gz: 03e54fc0b1eb177d39a1539f4aab9ed646aeab63f8b2e740900648c4a166090c
5
5
  SHA512:
6
- metadata.gz: 5cca348edd39f3d9d3eb0490b0bc8e1d6db7d7cd2a1e9dbc61bf19e97f2f937c673aae2d12b4fbf59dc96f898917b40129f19e8e655edb2c3808897d9bdefc80
7
- data.tar.gz: e7c64c391cc83b34cac1d1785e4ddc07f521123394d0555031c296ceda4d2cc7c7a3d858a31e2e1f9bc79cf9eb0caf2d3ce2b6eeb1c86b7c265567141deb7b1c
6
+ metadata.gz: f7c8867a82ee9985bb2ef69a3561daece76d54ad5431df2294d2f169a9a9c755801c39b7f482935bcac657182957d1a1ef71388d11c9be7803603b32e89833d5
7
+ data.tar.gz: 90902a467729cbaabd15c80d1690208ec09000a768976243f7babfca83d791701a73aecd421bc07b12c910da2c0e14d05c03cd65cae81dbacd7f2f55fc76cd88
@@ -4,4 +4,4 @@
4
4
 
5
5
  require_relative '../config/environment'
6
6
 
7
- CLI.new.call
7
+ FruitInfo::CLI.new.call
data/lib/cli.rb CHANGED
@@ -1,96 +1,77 @@
1
1
  # frozen_string_literal: false
2
2
 
3
3
  # displays a menu and loops menu until user inputs q
4
- class CLI
5
- def call
6
- FruityviceAPI.new.make_fruits
7
- puts 'Welcome to fruit!'
8
- input = nil
9
- while input != 'q'
10
- puts 'Press ' + 'a'.red + ' to see all fruit'
11
- puts 'Press ' + 's'.yellow + ' to see all fruit listed with their scientific names'
12
- puts 'Press ' + 'n'.light_yellow + ' to see all fruit listed with their nutrional information'
13
- puts 'Press ' + 'm'.green + ' to see the fruits with most nutrition'
14
- puts 'Press ' + 'l'.cyan + ' to see the fruits with least nutrition'
15
- puts 'Type the ' + 'name of a fruit '.blue + 'to see all of its information'
16
- puts 'Press ' + 'q'.magenta + " to quit\n"
17
- print 'What would you like to do: '
18
- input = gets.strip.downcase
19
- case input
20
- when 'q'
21
- return
22
- when 'a'
23
- display_all_fruit
24
- when 's'
25
- display_fruits_with_scientific_names
26
- when 'n'
27
- display_nutrional_info
28
- when 'm'
29
- display_the_most
30
- when 'l'
31
- display_the_least
32
- else
33
- if !Fruit.all.find { |fruit| fruit.name.downcase == input}.nil?
34
- display_one_fruit(Fruit.all.find { |fruit| fruit.name.downcase == input })
4
+ module FruitInfo
5
+ class CLI
6
+ def call
7
+ FruityviceAPI.new.make_fruits
8
+ puts 'Welcome to fruit!'
9
+ input = nil
10
+ while input != 'q'
11
+ puts 'Press ' + 'a'.red + ' to see all fruit'
12
+ puts 'Press ' + 's'.yellow + ' to see all fruit listed with their scientific names'
13
+ puts 'Press ' + 'n'.light_yellow + ' to see all fruit listed with their nutrional information'
14
+ puts 'Press ' + 'm'.green + ' to see the fruits with most nutrition'
15
+ puts 'Press ' + 'l'.cyan + ' to see the fruits with least nutrition'
16
+ puts 'Type the ' + 'name of a fruit '.blue + 'to see all of its information'
17
+ puts 'Press ' + 'q'.magenta + " to quit\n"
18
+ print 'What would you like to do: '
19
+ input = gets.strip.downcase
20
+ case input
21
+ when 'q'
22
+ return
23
+ when 'a'
24
+ display_all_fruit
25
+ when 's'
26
+ display_fruits_with_scientific_names
27
+ when 'n'
28
+ display_nutrional_info
29
+ when 'm'
30
+ display_the_most
31
+ when 'l'
32
+ display_the_least
35
33
  else
36
- puts "\nNot a valid option or fruit in database\n".red
34
+ if !Fruit.all.find { |fruit| fruit.name.downcase == input}.nil?
35
+ display_one_fruit(Fruit.all.find { |fruit| fruit.name.downcase == input })
36
+ else
37
+ puts "\nNot a valid option or fruit in database\n".red
38
+ end
37
39
  end
38
40
  end
39
41
  end
40
- end
41
-
42
- def display_the_least
43
- puts "\nThe fruits with the least nutrition per 100g".colorize(:magenta)
44
- least_carb = Fruit.min('carbohydrates')
45
- least_protein = Fruit.min('protein')
46
- least_fat = Fruit.min('fat')
47
- least_calories = Fruit.min('calories')
48
- least_sugar = Fruit.min('sugar')
49
-
50
- puts "\nLeast carbohydrates: #{least_carb.name} @ #{least_carb.nutritions['carbohydrates']}g".colorize(least_carb.color)
51
- puts "Least protein: #{least_protein.name} @ #{least_protein.nutritions['protein']}g".colorize(least_protein.color)
52
- puts "Least fat: #{least_fat.name} @ #{least_fat.nutritions['fat']}g".colorize(least_fat.color)
53
- puts "Least calories: #{least_calories.name} @ #{least_calories.nutritions['calories']}".colorize(least_calories.color)
54
- puts "Least sugar: #{least_sugar.name} @ #{least_sugar.nutritions['sugar']}g\n".colorize(least_sugar.color)
55
- end
56
-
57
- def display_the_most
58
- puts "\nThe fruits with the most nutrition per 100g".colorize(:cyan)
59
- most_carb = Fruit.max('carbohydrates')
60
- most_protein = Fruit.max('protein')
61
- most_fat = Fruit.max('fat')
62
- most_calories = Fruit.max('calories')
63
- most_sugar = Fruit.max('sugar')
64
-
65
- puts "\nMost carbohydrates: #{most_carb.name} @ #{most_carb.nutritions['carbohydrates']}g".colorize(most_carb.color)
66
- puts "Most protein: #{most_protein.name} @ #{most_protein.nutritions['protein']}g".colorize(most_protein.color)
67
- puts "Most fat: #{most_fat.name} @ #{most_fat.nutritions['fat']}g".colorize(most_fat.color)
68
- puts "Most calories: #{most_calories.name} @ #{most_calories.nutritions['calories']}".colorize(most_calories.color)
69
- puts "Most sugar: #{most_sugar.name} @ #{most_sugar.nutritions['sugar']}g\n".colorize(most_sugar.color)
70
- end
71
-
72
- def display_one_fruit(fruit)
73
- puts "\n#{fruit.name} - #{fruit.order} #{fruit.family} #{fruit.genus}".colorize(fruit.color)
74
- fruit.nutritions.each do |k, v|
75
- if k == 'calories'
76
- puts "#{k}: #{v}".colorize(color: :black, background: fruit.color)
77
- else
78
- puts "#{k}: #{v}g".colorize(color: :black, background: fruit.color)
79
- end
42
+
43
+ def display_the_least
44
+ puts "\nThe fruits with the least nutrition per 100g".colorize(:magenta)
45
+ least_carb = Fruit.min('carbohydrates')
46
+ least_protein = Fruit.min('protein')
47
+ least_fat = Fruit.min('fat')
48
+ least_calories = Fruit.min('calories')
49
+ least_sugar = Fruit.min('sugar')
50
+
51
+ puts "\nLeast carbohydrates: #{least_carb.name} @ #{least_carb.nutritions['carbohydrates']}g".colorize(least_carb.color)
52
+ puts "Least protein: #{least_protein.name} @ #{least_protein.nutritions['protein']}g".colorize(least_protein.color)
53
+ puts "Least fat: #{least_fat.name} @ #{least_fat.nutritions['fat']}g".colorize(least_fat.color)
54
+ puts "Least calories: #{least_calories.name} @ #{least_calories.nutritions['calories']}".colorize(least_calories.color)
55
+ puts "Least sugar: #{least_sugar.name} @ #{least_sugar.nutritions['sugar']}g\n".colorize(least_sugar.color)
80
56
  end
81
- puts ''
82
- end
83
-
84
- def display_all_fruit
85
- puts ''
86
- Fruit.all.each { |fruit| puts fruit.name.to_s.colorize(fruit.color) }
87
- puts ''
88
- end
89
-
90
- def display_nutrional_info
91
- puts ''
92
- Fruit.all.each do |fruit|
93
- puts fruit.name.to_s.colorize(fruit.color) + ' per 100g'
57
+
58
+ def display_the_most
59
+ puts "\nThe fruits with the most nutrition per 100g".colorize(:cyan)
60
+ most_carb = Fruit.max('carbohydrates')
61
+ most_protein = Fruit.max('protein')
62
+ most_fat = Fruit.max('fat')
63
+ most_calories = Fruit.max('calories')
64
+ most_sugar = Fruit.max('sugar')
65
+
66
+ puts "\nMost carbohydrates: #{most_carb.name} @ #{most_carb.nutritions['carbohydrates']}g".colorize(most_carb.color)
67
+ puts "Most protein: #{most_protein.name} @ #{most_protein.nutritions['protein']}g".colorize(most_protein.color)
68
+ puts "Most fat: #{most_fat.name} @ #{most_fat.nutritions['fat']}g".colorize(most_fat.color)
69
+ puts "Most calories: #{most_calories.name} @ #{most_calories.nutritions['calories']}".colorize(most_calories.color)
70
+ puts "Most sugar: #{most_sugar.name} @ #{most_sugar.nutritions['sugar']}g\n".colorize(most_sugar.color)
71
+ end
72
+
73
+ def display_one_fruit(fruit)
74
+ puts "\n#{fruit.name} - #{fruit.order} #{fruit.family} #{fruit.genus}".colorize(fruit.color)
94
75
  fruit.nutritions.each do |k, v|
95
76
  if k == 'calories'
96
77
  puts "#{k}: #{v}".colorize(color: :black, background: fruit.color)
@@ -100,11 +81,32 @@ class CLI
100
81
  end
101
82
  puts ''
102
83
  end
84
+
85
+ def display_all_fruit
86
+ puts ''
87
+ Fruit.all.each { |fruit| puts fruit.name.to_s.colorize(fruit.color) }
88
+ puts ''
89
+ end
90
+
91
+ def display_nutrional_info
92
+ puts ''
93
+ Fruit.all.each do |fruit|
94
+ puts fruit.name.to_s.colorize(fruit.color) + ' per 100g'
95
+ fruit.nutritions.each do |k, v|
96
+ if k == 'calories'
97
+ puts "#{k}: #{v}".colorize(color: :black, background: fruit.color)
98
+ else
99
+ puts "#{k}: #{v}g".colorize(color: :black, background: fruit.color)
100
+ end
101
+ end
102
+ puts ''
103
+ end
104
+ end
105
+
106
+ def display_fruits_with_scientific_names
107
+ puts ''
108
+ Fruit.all.each { |fruit| puts "#{fruit.name}: #{fruit.order} #{fruit.family} #{fruit.genus}".colorize(fruit.color) }
109
+ puts ''
110
+ end
103
111
  end
104
-
105
- def display_fruits_with_scientific_names
106
- puts ''
107
- Fruit.all.each { |fruit| puts "#{fruit.name}: #{fruit.order} #{fruit.family} #{fruit.genus}".colorize(fruit.color) }
108
- puts ''
109
- end
110
- end
112
+ end
@@ -1,61 +1,65 @@
1
1
  # frozen_string_literal: false
2
2
 
3
3
  # a class to hold the fruits information inculding a hash of nutritional facts
4
- class Fruit
5
- attr_accessor :genus, :name, :id, :family, :order, :nutritions, :color
6
- @@all = []
7
- def initialize(attributes)
8
- attributes.each { |k, v| send("#{k}=", v) }
9
- add_color
10
- @@all << self
11
- end
4
+ module FruitInfo
5
+ class Fruit
6
+ attr_accessor :genus, :name, :id, :family, :order, :nutritions, :color
7
+ @@all = []
8
+ def initialize(attributes)
9
+ attributes.each { |k, v| send("#{k}=", v) }
10
+ add_color
11
+ @@all << self
12
+ end
12
13
 
13
- def self.max(element)
14
- all.max { |a, b| a.nutritions[element] <=> b.nutritions[element] }
15
- end
14
+ def self.max(element)
15
+ all.max { |a, b| a.nutritions[element] <=> b.nutritions[element] }
16
+ end
16
17
 
17
- def self.min(element)
18
- all.min { |a, b| a.nutritions[element] <=> b.nutritions[element] }
19
- end
18
+ def self.min(element)
19
+ all.min { |a, b| a.nutritions[element] <=> b.nutritions[element] }
20
+ end
20
21
 
21
- def add_color
22
- case name
23
- when 'Banana'
24
- self.color = :light_yellow
25
- when 'Blueberry'
26
- self.color = :blue
27
- when 'Cherry'
28
- self.color = :red
29
- when 'Apple'
30
- self.color = :green
31
- when 'Lemon'
32
- self.color = :light_yellow
33
- when 'Mango'
34
- self.color = :yellow
35
- when 'Orange'
36
- self.color = :yellow
37
- when 'Pear'
38
- self.color = :green
39
- when 'Pineapple'
40
- self.color = :light_yellow
41
- when 'Raspberry'
42
- self.color = :light_red
43
- when 'Strawberry'
44
- self.color = :red
45
- when 'Tomato'
46
- self.color = :red
47
- when 'Watermelon'
48
- self.color = :light_green
49
- else
50
- self.color = :white
22
+ def add_color
23
+ case name
24
+ when 'Apricot'
25
+ self.color = :yellow
26
+ when 'Banana'
27
+ self.color = :light_yellow
28
+ when 'Blueberry'
29
+ self.color = :blue
30
+ when 'Cherry'
31
+ self.color = :red
32
+ when 'Apple'
33
+ self.color = :green
34
+ when 'Lemon'
35
+ self.color = :light_yellow
36
+ when 'Mango'
37
+ self.color = :yellow
38
+ when 'Orange'
39
+ self.color = :yellow
40
+ when 'Pear'
41
+ self.color = :green
42
+ when 'Pineapple'
43
+ self.color = :light_yellow
44
+ when 'Raspberry'
45
+ self.color = :light_red
46
+ when 'Strawberry'
47
+ self.color = :red
48
+ when 'Tomato'
49
+ self.color = :red
50
+ when 'Watermelon'
51
+ self.color = :light_green
52
+ else
53
+ self.color = :white
54
+ end
51
55
  end
52
- end
53
56
 
54
- def self.all
55
- @@all
56
- end
57
+ def self.all
58
+ @@all
59
+ end
57
60
 
58
- def self.new_from_api(fruits)
59
- fruits.each { |fruit| new(fruit) }
61
+ def self.new_from_api(fruits)
62
+ fruits.each { |fruit| new(fruit) }
63
+ end
60
64
  end
61
- end
65
+ end
@@ -1,14 +1,16 @@
1
1
  # frozen_string_literal: false
2
2
 
3
3
  # accesses the fruityvice api, parses it, and calls Fruit class to make fruit from parsed hash
4
- class FruityviceAPI
5
- BASE_URL = 'https://www.fruityvice.com/api/fruit/all'
4
+ module FruitInfo
5
+ class FruityviceAPI
6
+ BASE_URL = 'https://www.fruityvice.com/api/fruit/all'
6
7
 
7
- def access_fruityviceapi
8
- JSON.parse(HTTParty.get(BASE_URL, verify: false))
9
- end
8
+ def access_fruityviceapi
9
+ JSON.parse(HTTParty.get(BASE_URL, verify: false))
10
+ end
10
11
 
11
- def make_fruits
12
- Fruit.new_from_api(access_fruityviceapi)
12
+ def make_fruits
13
+ Fruit.new_from_api(access_fruityviceapi)
14
+ end
13
15
  end
14
- end
16
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fruit-info
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Grasse-Haroldsen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-08 00:00:00.000000000 Z
11
+ date: 2020-12-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  - !ruby/object:Gem::Version
99
99
  version: '0'
100
100
  requirements: []
101
- rubygems_version: 3.0.6
101
+ rubygems_version: 3.0.8
102
102
  signing_key:
103
103
  specification_version: 4
104
104
  summary: A gem utilizing the fruityvice api