fruit-info 0.1.6 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 14edf24625be9c5f471ad5c2907fe315348685673588542129172bebbc91c580
4
- data.tar.gz: 9cee80fba89a37300a887dfcd716a019116e99ee0ee735662830998abf0bca81
3
+ metadata.gz: 13b2a93a47f9040aefb4976f067932d7e45fdf8fcbb0e41ee3798ad9615f99f8
4
+ data.tar.gz: ae6028b74f34e5ba57a4e54a98eb651686dd1bfd318428cbb7200b1b860ec47e
5
5
  SHA512:
6
- metadata.gz: 51dbca0c566aaf8c7cd72e14694be6af09a03323bc72d89362cb149952a5b869c4af742d95f4e00621dd93886d68e074f56dcd7bcba878f1b4cdcb24d7ea9d8f
7
- data.tar.gz: 86278e51c80ad788dc46414e0a19d9af951b7083c37a096dea2f4022ae8c360a8ac0d7cae343e12793474b40ba9048d175824518d1582fb88ce8f454ed8536cf
6
+ metadata.gz: 77c4bffeaa3c5f6903eedea89b6fa055f249cb34e5c252ca7d5cfae01e4ccf4e7c4784fdcfa12599e35366d7e7e1755c7e7fe5aed39cbe7d6a0d827d1d5aca40
7
+ data.tar.gz: c36e7c69dcc9fd411443783079928f8e6779134b3e4467568ea754c6ea30e810a859f5d8f4bcbe354fc1310bc56e15d8559cfbea497fc47f89ba346fb8626c53
@@ -5,6 +5,6 @@ require 'pry'
5
5
  require 'json'
6
6
  require 'colorize'
7
7
 
8
- require_relative '../lib/fruit.rb'
9
- require_relative '../lib/cli.rb'
10
- require_relative '../lib/fruityvice_api.rb'
8
+ require_relative '../lib/fruit'
9
+ require_relative '../lib/cli'
10
+ require_relative '../lib/fruityvice_api'
data/lib/cli.rb CHANGED
@@ -7,18 +7,18 @@ module FruitInfo
7
7
  FruityviceAPI.new.make_fruits
8
8
  puts 'Welcome to fruit!'
9
9
  input = nil
10
- while input != 'q'
10
+ while input != 'q' || input != 'exit'
11
11
  puts 'Press ' + 'a'.red + ' to see all fruit'
12
12
  puts 'Press ' + 's'.yellow + ' to see all fruit listed with their scientific names'
13
13
  puts 'Press ' + 'n'.light_yellow + ' to see all fruit listed with their nutrional information'
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 + " to quit\n"
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'
21
+ when 'q', 'exit'
22
22
  return
23
23
  when 'a'
24
24
  display_all_fruit
@@ -31,7 +31,7 @@ module FruitInfo
31
31
  when 'l'
32
32
  display_the_least
33
33
  else
34
- if !Fruit.all.find { |fruit| fruit.name.downcase == input}.nil?
34
+ if !Fruit.all.find { |fruit| fruit.name.downcase == input }.nil?
35
35
  display_one_fruit(Fruit.all.find { |fruit| fruit.name.downcase == input })
36
36
  else
37
37
  puts "\nNot a valid option or fruit in database\n".red
@@ -39,7 +39,7 @@ module FruitInfo
39
39
  end
40
40
  end
41
41
  end
42
-
42
+
43
43
  def display_the_least
44
44
  puts "\nThe fruits with the least nutrition per 100g".colorize(:magenta)
45
45
  least_carb = Fruit.min('carbohydrates')
@@ -47,14 +47,14 @@ module FruitInfo
47
47
  least_fat = Fruit.min('fat')
48
48
  least_calories = Fruit.min('calories')
49
49
  least_sugar = Fruit.min('sugar')
50
-
50
+
51
51
  puts "\nLeast carbohydrates: #{least_carb.name} @ #{least_carb.nutritions['carbohydrates']}g".colorize(least_carb.color)
52
52
  puts "Least protein: #{least_protein.name} @ #{least_protein.nutritions['protein']}g".colorize(least_protein.color)
53
53
  puts "Least fat: #{least_fat.name} @ #{least_fat.nutritions['fat']}g".colorize(least_fat.color)
54
54
  puts "Least calories: #{least_calories.name} @ #{least_calories.nutritions['calories']}".colorize(least_calories.color)
55
55
  puts "Least sugar: #{least_sugar.name} @ #{least_sugar.nutritions['sugar']}g\n".colorize(least_sugar.color)
56
56
  end
57
-
57
+
58
58
  def display_the_most
59
59
  puts "\nThe fruits with the most nutrition per 100g".colorize(:cyan)
60
60
  most_carb = Fruit.max('carbohydrates')
@@ -62,14 +62,14 @@ module FruitInfo
62
62
  most_fat = Fruit.max('fat')
63
63
  most_calories = Fruit.max('calories')
64
64
  most_sugar = Fruit.max('sugar')
65
-
65
+
66
66
  puts "\nMost carbohydrates: #{most_carb.name} @ #{most_carb.nutritions['carbohydrates']}g".colorize(most_carb.color)
67
67
  puts "Most protein: #{most_protein.name} @ #{most_protein.nutritions['protein']}g".colorize(most_protein.color)
68
68
  puts "Most fat: #{most_fat.name} @ #{most_fat.nutritions['fat']}g".colorize(most_fat.color)
69
69
  puts "Most calories: #{most_calories.name} @ #{most_calories.nutritions['calories']}".colorize(most_calories.color)
70
70
  puts "Most sugar: #{most_sugar.name} @ #{most_sugar.nutritions['sugar']}g\n".colorize(most_sugar.color)
71
71
  end
72
-
72
+
73
73
  def display_one_fruit(fruit)
74
74
  puts "\n#{fruit.name} - #{fruit.order} #{fruit.family} #{fruit.genus}".colorize(fruit.color)
75
75
  fruit.nutritions.each do |k, v|
@@ -81,13 +81,13 @@ module FruitInfo
81
81
  end
82
82
  puts ''
83
83
  end
84
-
84
+
85
85
  def display_all_fruit
86
86
  puts ''
87
87
  Fruit.all.each { |fruit| puts fruit.name.to_s.colorize(fruit.color) }
88
88
  puts ''
89
89
  end
90
-
90
+
91
91
  def display_nutrional_info
92
92
  puts ''
93
93
  Fruit.all.each do |fruit|
@@ -102,11 +102,13 @@ module FruitInfo
102
102
  puts ''
103
103
  end
104
104
  end
105
-
105
+
106
106
  def display_fruits_with_scientific_names
107
107
  puts ''
108
- Fruit.all.each { |fruit| puts "#{fruit.name}: #{fruit.order} #{fruit.family} #{fruit.genus}".colorize(fruit.color) }
108
+ Fruit.all.each do |fruit|
109
+ puts "#{fruit.name}: #{fruit.order} #{fruit.family} #{fruit.genus}".colorize(fruit.color)
110
+ end
109
111
  puts ''
110
112
  end
111
113
  end
112
- end
114
+ 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,38 +21,40 @@ module FruitInfo
20
21
  end
21
22
 
22
23
  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
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
55
58
  end
56
59
 
57
60
  def self.all
@@ -62,4 +65,4 @@ module FruitInfo
62
65
  fruits.each { |fruit| new(fruit) }
63
66
  end
64
67
  end
65
- end
68
+ end
@@ -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
- JSON.parse(HTTParty.get(BASE_URL, verify: false))
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
- Fruit.new_from_api(access_fruityviceapi)
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.6
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: 2020-12-26 00:00:00.000000000 Z
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.18'
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.18'
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: 2.3.0
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: 3.0.8
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: []