fruit-info 0.1.7 → 0.1.8
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 +4 -4
- data/config/environment.rb +3 -3
- data/lib/cli.rb +14 -14
- data/lib/fruit.rb +35 -34
- data/lib/fruityvice_api.rb +9 -3
- metadata +6 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 13b2a93a47f9040aefb4976f067932d7e45fdf8fcbb0e41ee3798ad9615f99f8
|
|
4
|
+
data.tar.gz: ae6028b74f34e5ba57a4e54a98eb651686dd1bfd318428cbb7200b1b860ec47e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 77c4bffeaa3c5f6903eedea89b6fa055f249cb34e5c252ca7d5cfae01e4ccf4e7c4784fdcfa12599e35366d7e7e1755c7e7fe5aed39cbe7d6a0d827d1d5aca40
|
|
7
|
+
data.tar.gz: c36e7c69dcc9fd411443783079928f8e6779134b3e4467568ea754c6ea30e810a859f5d8f4bcbe354fc1310bc56e15d8559cfbea497fc47f89ba346fb8626c53
|
data/config/environment.rb
CHANGED
|
@@ -5,6 +5,6 @@ require 'pry'
|
|
|
5
5
|
require 'json'
|
|
6
6
|
require 'colorize'
|
|
7
7
|
|
|
8
|
-
require_relative '../lib/fruit
|
|
9
|
-
require_relative '../lib/cli
|
|
10
|
-
require_relative '../lib/fruityvice_api
|
|
8
|
+
require_relative '../lib/fruit'
|
|
9
|
+
require_relative '../lib/cli'
|
|
10
|
+
require_relative '../lib/fruityvice_api'
|
data/lib/cli.rb
CHANGED
|
@@ -14,13 +14,11 @@ module FruitInfo
|
|
|
14
14
|
puts 'Press ' + 'm'.green + ' to see the fruits with most nutrition'
|
|
15
15
|
puts 'Press ' + 'l'.cyan + ' to see the fruits with least nutrition'
|
|
16
16
|
puts 'Type the ' + 'name of a fruit '.blue + 'to see all of its information'
|
|
17
|
-
puts 'Press ' + 'q'.magenta +
|
|
17
|
+
puts 'Press ' + 'q'.magenta + ' or type ' + 'exit'.magenta + " to quit\n"
|
|
18
18
|
print 'What would you like to do: '
|
|
19
19
|
input = gets.strip.downcase
|
|
20
20
|
case input
|
|
21
|
-
when 'q'
|
|
22
|
-
return
|
|
23
|
-
when 'exit'
|
|
21
|
+
when 'q', 'exit'
|
|
24
22
|
return
|
|
25
23
|
when 'a'
|
|
26
24
|
display_all_fruit
|
|
@@ -33,7 +31,7 @@ module FruitInfo
|
|
|
33
31
|
when 'l'
|
|
34
32
|
display_the_least
|
|
35
33
|
else
|
|
36
|
-
if !Fruit.all.find { |fruit| fruit.name.downcase == input}.nil?
|
|
34
|
+
if !Fruit.all.find { |fruit| fruit.name.downcase == input }.nil?
|
|
37
35
|
display_one_fruit(Fruit.all.find { |fruit| fruit.name.downcase == input })
|
|
38
36
|
else
|
|
39
37
|
puts "\nNot a valid option or fruit in database\n".red
|
|
@@ -41,7 +39,7 @@ module FruitInfo
|
|
|
41
39
|
end
|
|
42
40
|
end
|
|
43
41
|
end
|
|
44
|
-
|
|
42
|
+
|
|
45
43
|
def display_the_least
|
|
46
44
|
puts "\nThe fruits with the least nutrition per 100g".colorize(:magenta)
|
|
47
45
|
least_carb = Fruit.min('carbohydrates')
|
|
@@ -49,14 +47,14 @@ module FruitInfo
|
|
|
49
47
|
least_fat = Fruit.min('fat')
|
|
50
48
|
least_calories = Fruit.min('calories')
|
|
51
49
|
least_sugar = Fruit.min('sugar')
|
|
52
|
-
|
|
50
|
+
|
|
53
51
|
puts "\nLeast carbohydrates: #{least_carb.name} @ #{least_carb.nutritions['carbohydrates']}g".colorize(least_carb.color)
|
|
54
52
|
puts "Least protein: #{least_protein.name} @ #{least_protein.nutritions['protein']}g".colorize(least_protein.color)
|
|
55
53
|
puts "Least fat: #{least_fat.name} @ #{least_fat.nutritions['fat']}g".colorize(least_fat.color)
|
|
56
54
|
puts "Least calories: #{least_calories.name} @ #{least_calories.nutritions['calories']}".colorize(least_calories.color)
|
|
57
55
|
puts "Least sugar: #{least_sugar.name} @ #{least_sugar.nutritions['sugar']}g\n".colorize(least_sugar.color)
|
|
58
56
|
end
|
|
59
|
-
|
|
57
|
+
|
|
60
58
|
def display_the_most
|
|
61
59
|
puts "\nThe fruits with the most nutrition per 100g".colorize(:cyan)
|
|
62
60
|
most_carb = Fruit.max('carbohydrates')
|
|
@@ -64,14 +62,14 @@ module FruitInfo
|
|
|
64
62
|
most_fat = Fruit.max('fat')
|
|
65
63
|
most_calories = Fruit.max('calories')
|
|
66
64
|
most_sugar = Fruit.max('sugar')
|
|
67
|
-
|
|
65
|
+
|
|
68
66
|
puts "\nMost carbohydrates: #{most_carb.name} @ #{most_carb.nutritions['carbohydrates']}g".colorize(most_carb.color)
|
|
69
67
|
puts "Most protein: #{most_protein.name} @ #{most_protein.nutritions['protein']}g".colorize(most_protein.color)
|
|
70
68
|
puts "Most fat: #{most_fat.name} @ #{most_fat.nutritions['fat']}g".colorize(most_fat.color)
|
|
71
69
|
puts "Most calories: #{most_calories.name} @ #{most_calories.nutritions['calories']}".colorize(most_calories.color)
|
|
72
70
|
puts "Most sugar: #{most_sugar.name} @ #{most_sugar.nutritions['sugar']}g\n".colorize(most_sugar.color)
|
|
73
71
|
end
|
|
74
|
-
|
|
72
|
+
|
|
75
73
|
def display_one_fruit(fruit)
|
|
76
74
|
puts "\n#{fruit.name} - #{fruit.order} #{fruit.family} #{fruit.genus}".colorize(fruit.color)
|
|
77
75
|
fruit.nutritions.each do |k, v|
|
|
@@ -83,13 +81,13 @@ module FruitInfo
|
|
|
83
81
|
end
|
|
84
82
|
puts ''
|
|
85
83
|
end
|
|
86
|
-
|
|
84
|
+
|
|
87
85
|
def display_all_fruit
|
|
88
86
|
puts ''
|
|
89
87
|
Fruit.all.each { |fruit| puts fruit.name.to_s.colorize(fruit.color) }
|
|
90
88
|
puts ''
|
|
91
89
|
end
|
|
92
|
-
|
|
90
|
+
|
|
93
91
|
def display_nutrional_info
|
|
94
92
|
puts ''
|
|
95
93
|
Fruit.all.each do |fruit|
|
|
@@ -104,10 +102,12 @@ module FruitInfo
|
|
|
104
102
|
puts ''
|
|
105
103
|
end
|
|
106
104
|
end
|
|
107
|
-
|
|
105
|
+
|
|
108
106
|
def display_fruits_with_scientific_names
|
|
109
107
|
puts ''
|
|
110
|
-
Fruit.all.each
|
|
108
|
+
Fruit.all.each do |fruit|
|
|
109
|
+
puts "#{fruit.name}: #{fruit.order} #{fruit.family} #{fruit.genus}".colorize(fruit.color)
|
|
110
|
+
end
|
|
111
111
|
puts ''
|
|
112
112
|
end
|
|
113
113
|
end
|
data/lib/fruit.rb
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
module FruitInfo
|
|
5
5
|
class Fruit
|
|
6
6
|
attr_accessor :genus, :name, :id, :family, :order, :nutritions, :color
|
|
7
|
+
|
|
7
8
|
@@all = []
|
|
8
9
|
def initialize(attributes)
|
|
9
10
|
attributes.each { |k, v| send("#{k}=", v) }
|
|
@@ -20,40 +21,40 @@ module FruitInfo
|
|
|
20
21
|
end
|
|
21
22
|
|
|
22
23
|
def add_color
|
|
23
|
-
case name
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
24
|
+
self.color = case name
|
|
25
|
+
when 'Apricot'
|
|
26
|
+
:yellow
|
|
27
|
+
when 'Banana'
|
|
28
|
+
:light_yellow
|
|
29
|
+
when 'Blueberry'
|
|
30
|
+
:blue
|
|
31
|
+
when 'Cherry'
|
|
32
|
+
:red
|
|
33
|
+
when 'Apple'
|
|
34
|
+
:green
|
|
35
|
+
when 'Lemon'
|
|
36
|
+
:light_yellow
|
|
37
|
+
when 'Mango'
|
|
38
|
+
:yellow
|
|
39
|
+
when 'Orange'
|
|
40
|
+
:yellow
|
|
41
|
+
when 'Pear'
|
|
42
|
+
:green
|
|
43
|
+
when 'Pineapple'
|
|
44
|
+
:light_yellow
|
|
45
|
+
when 'Raspberry'
|
|
46
|
+
:light_red
|
|
47
|
+
when 'Strawberry'
|
|
48
|
+
:red
|
|
49
|
+
when 'Tomato'
|
|
50
|
+
:red
|
|
51
|
+
when 'Watermelon'
|
|
52
|
+
:light_green
|
|
53
|
+
when 'Guava'
|
|
54
|
+
:light_green
|
|
55
|
+
else
|
|
56
|
+
:white
|
|
57
|
+
end
|
|
57
58
|
end
|
|
58
59
|
|
|
59
60
|
def self.all
|
data/lib/fruityvice_api.rb
CHANGED
|
@@ -6,11 +6,17 @@ module FruitInfo
|
|
|
6
6
|
BASE_URL = 'https://www.fruityvice.com/api/fruit/all'
|
|
7
7
|
|
|
8
8
|
def access_fruityviceapi
|
|
9
|
-
|
|
9
|
+
resp = HTTParty.get(BASE_URL, verify: false)
|
|
10
|
+
return JSON.parse(resp.to_s) if resp
|
|
11
|
+
|
|
12
|
+
nil
|
|
10
13
|
end
|
|
11
14
|
|
|
12
15
|
def make_fruits
|
|
13
|
-
|
|
16
|
+
fruit_json = access_fruityviceapi
|
|
17
|
+
return unless fruit_json
|
|
18
|
+
|
|
19
|
+
Fruit.new_from_api(fruit_json)
|
|
14
20
|
end
|
|
15
21
|
end
|
|
16
|
-
end
|
|
22
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
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.8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Samuel Grasse-Haroldsen
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: colorize
|
|
@@ -30,14 +29,14 @@ dependencies:
|
|
|
30
29
|
requirements:
|
|
31
30
|
- - "~>"
|
|
32
31
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '0.
|
|
32
|
+
version: '0.24'
|
|
34
33
|
type: :runtime
|
|
35
34
|
prerelease: false
|
|
36
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
36
|
requirements:
|
|
38
37
|
- - "~>"
|
|
39
38
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: '0.
|
|
39
|
+
version: '0.24'
|
|
41
40
|
- !ruby/object:Gem::Dependency
|
|
42
41
|
name: json
|
|
43
42
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -83,7 +82,6 @@ homepage: https://github.com/SamG-H/fruit-cli-gem
|
|
|
83
82
|
licenses:
|
|
84
83
|
- MIT
|
|
85
84
|
metadata: {}
|
|
86
|
-
post_install_message:
|
|
87
85
|
rdoc_options: []
|
|
88
86
|
require_paths:
|
|
89
87
|
- lib
|
|
@@ -91,15 +89,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
91
89
|
requirements:
|
|
92
90
|
- - ">="
|
|
93
91
|
- !ruby/object:Gem::Version
|
|
94
|
-
version:
|
|
92
|
+
version: 3.3.0
|
|
95
93
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
94
|
requirements:
|
|
97
95
|
- - ">="
|
|
98
96
|
- !ruby/object:Gem::Version
|
|
99
97
|
version: '0'
|
|
100
98
|
requirements: []
|
|
101
|
-
rubygems_version:
|
|
102
|
-
signing_key:
|
|
99
|
+
rubygems_version: 4.0.16
|
|
103
100
|
specification_version: 4
|
|
104
101
|
summary: A gem utilizing the fruityvice api
|
|
105
102
|
test_files: []
|