nuts_snacks 0.1.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 +7 -0
- data/bin/snacks +8 -0
- data/config/environment.rb +8 -0
- data/lib/snacks.rb +8 -0
- data/lib/snacks/cli.rb +67 -0
- data/lib/snacks/nutsdata.rb +33 -0
- data/lib/snacks/scraper.rb +12 -0
- data/lib/snacks/version.rb +3 -0
- metadata +79 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6642ebaf793794d49452d03fc3aa7b8459c7aa735a7bda237126c8c8133b6b22
|
4
|
+
data.tar.gz: 7b2643288928171c6581985bd87ee55f58a57c9bd619b6369484460f56cbfb95
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 84faec6843d864fb0b60257b1c2c986c8ba18c37f895586a18a848cbc6db17fda57b939cc6e0260dea0371748cbfc57a0e51965514bc5ba5bde68931104ea91b
|
7
|
+
data.tar.gz: 1092b8e49f8950e607488143102e95d86fc99f2659613bd6ca0a9e87cc0f97786d13c71e6b2e587797e14391922ffcb5a97e58ab7d164ff19a011298215895f0
|
data/bin/snacks
ADDED
data/lib/snacks.rb
ADDED
data/lib/snacks/cli.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
class Snacks::CLI
|
2
|
+
|
3
|
+
def call
|
4
|
+
intro
|
5
|
+
show_nuts_list
|
6
|
+
show_data
|
7
|
+
choose_another?
|
8
|
+
# goodbye
|
9
|
+
end
|
10
|
+
|
11
|
+
def intro
|
12
|
+
puts "Hi, Welcome to Nuts!"
|
13
|
+
# sleep 2
|
14
|
+
puts "Here is a list of some of the most common nuts!"
|
15
|
+
# sleep 2
|
16
|
+
end
|
17
|
+
|
18
|
+
def show_nuts_list
|
19
|
+
these = Snacks::NutsData.new #Snacks::NutData
|
20
|
+
these.nuts.each.with_index(1) do |nut, index|
|
21
|
+
puts "\n#{index}. #{nut.capitalize}"
|
22
|
+
end
|
23
|
+
# sleep 2
|
24
|
+
end
|
25
|
+
|
26
|
+
def user_chooses_nut
|
27
|
+
while true
|
28
|
+
print "\nChoose the list number of the nut that you're interested in: "
|
29
|
+
input = gets.chomp.to_i - 1
|
30
|
+
if !(0..7).include?(input)
|
31
|
+
puts "Please enter a number between 1 and 8"
|
32
|
+
else
|
33
|
+
break
|
34
|
+
end
|
35
|
+
end
|
36
|
+
input
|
37
|
+
end
|
38
|
+
|
39
|
+
def show_data
|
40
|
+
data = Snacks::NutsData.about_nut_info
|
41
|
+
puts "\n========== #{data.type} =========="
|
42
|
+
data.nut_facts.each do |fact|
|
43
|
+
puts fact
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def choose_another?
|
48
|
+
while true
|
49
|
+
print "\nWould you like to choose another nut variety to learn more about: (y/n) "
|
50
|
+
input = gets.chomp.downcase.to_s
|
51
|
+
if input == "y"
|
52
|
+
show_nuts_list
|
53
|
+
show_data
|
54
|
+
elsif input == "n"
|
55
|
+
goodbye
|
56
|
+
else
|
57
|
+
puts "\nPlease choose (y/n)."
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def goodbye
|
63
|
+
puts "\nThank you for visiting, see you next time!"
|
64
|
+
exit!
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class Snacks::NutsData
|
2
|
+
|
3
|
+
attr_reader :type, :nut_facts
|
4
|
+
|
5
|
+
def initialize(type=nil, nut_facts=nil)
|
6
|
+
@type = type
|
7
|
+
@nut_facts = nut_facts
|
8
|
+
end
|
9
|
+
|
10
|
+
def nuts
|
11
|
+
nuts = ["almonds", "brazilNuts", "cashews", "hazelnuts", "macadamiaNuts", "peanuts","pecans", "pistachios"]
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.all
|
15
|
+
@@all << self
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.about_nut_info #=> onject <NutsData302405205>.type & facts
|
19
|
+
scraper_obj = Snacks::Scraper.new # gives access to all data in Scraper class
|
20
|
+
doc = scraper_obj.get_page
|
21
|
+
type_aka_header = doc.css("div.plp h1").text
|
22
|
+
|
23
|
+
"\nAbout #{type_aka_header}"
|
24
|
+
facts = doc.css("div.formatted-content.description p").collect do |p|
|
25
|
+
"\n#{p.text}" if !p.text.start_with?("We also")
|
26
|
+
end
|
27
|
+
self.new(type_aka_header, facts)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nuts_snacks
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- RachelCodesToo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-11-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: will list nutrition facts of all their snack offerings
|
42
|
+
email:
|
43
|
+
- a.r.fausto@gmail.com
|
44
|
+
executables:
|
45
|
+
- snacks
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- bin/snacks
|
50
|
+
- config/environment.rb
|
51
|
+
- lib/snacks.rb
|
52
|
+
- lib/snacks/cli.rb
|
53
|
+
- lib/snacks/nutsdata.rb
|
54
|
+
- lib/snacks/scraper.rb
|
55
|
+
- lib/snacks/version.rb
|
56
|
+
homepage: https://github.com/RachelCodesToo/snacks
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubygems_version: 3.0.2
|
76
|
+
signing_key:
|
77
|
+
specification_version: 4
|
78
|
+
summary: A program that retrieves data from Nuts.com
|
79
|
+
test_files: []
|