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 +4 -4
- data/bin/fruit-info +1 -1
- data/lib/cli.rb +94 -92
- data/lib/fruit.rb +55 -51
- data/lib/fruityvice_api.rb +10 -8
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 242c602ab47c169cab13bc0c2c0e312bbd425544707cecf7cab29183b51c5063
|
4
|
+
data.tar.gz: 03e54fc0b1eb177d39a1539f4aab9ed646aeab63f8b2e740900648c4a166090c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7c8867a82ee9985bb2ef69a3561daece76d54ad5431df2294d2f169a9a9c755801c39b7f482935bcac657182957d1a1ef71388d11c9be7803603b32e89833d5
|
7
|
+
data.tar.gz: 90902a467729cbaabd15c80d1690208ec09000a768976243f7babfca83d791701a73aecd421bc07b12c910da2c0e14d05c03cd65cae81dbacd7f2f55fc76cd88
|
data/bin/fruit-info
CHANGED
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
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
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
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
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
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
puts
|
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
|
data/lib/fruit.rb
CHANGED
@@ -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
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
14
|
-
|
15
|
-
|
14
|
+
def self.max(element)
|
15
|
+
all.max { |a, b| a.nutritions[element] <=> b.nutritions[element] }
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
def self.min(element)
|
19
|
+
all.min { |a, b| a.nutritions[element] <=> b.nutritions[element] }
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
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
|
-
|
55
|
-
|
56
|
-
|
57
|
+
def self.all
|
58
|
+
@@all
|
59
|
+
end
|
57
60
|
|
58
|
-
|
59
|
-
|
61
|
+
def self.new_from_api(fruits)
|
62
|
+
fruits.each { |fruit| new(fruit) }
|
63
|
+
end
|
60
64
|
end
|
61
|
-
end
|
65
|
+
end
|
data/lib/fruityvice_api.rb
CHANGED
@@ -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
|
-
|
5
|
-
|
4
|
+
module FruitInfo
|
5
|
+
class FruityviceAPI
|
6
|
+
BASE_URL = 'https://www.fruityvice.com/api/fruit/all'
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
def access_fruityviceapi
|
9
|
+
JSON.parse(HTTParty.get(BASE_URL, verify: false))
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
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.
|
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-
|
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.
|
101
|
+
rubygems_version: 3.0.8
|
102
102
|
signing_key:
|
103
103
|
specification_version: 4
|
104
104
|
summary: A gem utilizing the fruityvice api
|