coffeebreak 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +2 -0
- data/bin/coffee_time +5 -0
- data/bin/console +9 -0
- data/bin/setup +1 -0
- data/coffeebreak.gemspec +31 -0
- data/lib/beans.rb +22 -0
- data/lib/cli.rb +122 -0
- data/lib/coffeebreak.rb +8 -0
- data/lib/scraper.rb +28 -0
- data/lib/scraper2.rb +28 -0
- data/lib/version.rb +3 -0
- metadata +90 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0f658c012f3f01d6a7bc3f0150fc0a607bf2447840e525b9abaae4a4f03656d5
|
4
|
+
data.tar.gz: ff13fe7744ac797fc8a3f12abb2e70c6e72a851753c1585db5a611bab629c0c0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b014fba445925d12925bdc950475049967f474d67474ca8deb160b3fd0d0eeb6b4c104965ab43c1c1ff7faf2fdd7f24f302cd13850453825f1ea42808178fd5e
|
7
|
+
data.tar.gz: e4aff878840ee7f4bab211fb7dbd25dbbc10b4e38d33dee98d8cd29b778b39daedada911aad608c71fd88a5488620d19f6caa4e50341316453e0bad9392f390a
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at sceptral.img@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Shirlen Detablan
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# CoffeeBreak
|
2
|
+
|
3
|
+
Welcome to the CoffeeBreak gem! This gem allows the user to look through the selections of available coffee at Playeronecoffee's website.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'coffeebreak'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install coffeebreak
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Access the coffee collection from PlayerOneCoffee's website!
|
24
|
+
|
25
|
+
## Development
|
26
|
+
|
27
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
28
|
+
|
29
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Ro5hi/coffee_break. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/Ro5hi/coffee_break/blob/master/CODE_OF_CONDUCT.md).
|
34
|
+
|
35
|
+
## License
|
36
|
+
|
37
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
38
|
+
|
39
|
+
## Code of Conduct
|
40
|
+
|
41
|
+
Everyone interacting in the CoffeeBreak project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/Ro5hi/coffee_break/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/coffee_time
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
#!/usr/bin/env bash
|
data/coffeebreak.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative 'lib/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "coffeebreak"
|
5
|
+
spec.version = CoffeeBreak::VERSION
|
6
|
+
spec.authors = ["Shirlen Detablan"]
|
7
|
+
spec.email = ["slen.detablan@gmail.com"]
|
8
|
+
|
9
|
+
spec.summary = %q{View coffee products on PlayerOneCoffee.}
|
10
|
+
spec.description = %q{Available products will display their roast type, price, and description.}
|
11
|
+
spec.homepage = "https://github.com/Ro5hi/coffee_break"
|
12
|
+
spec.license = "MIT"
|
13
|
+
|
14
|
+
spec.metadata["homepage_uri"] = "https://github.com/Ro5hi/coffee_break"
|
15
|
+
spec.metadata["source_code_uri"] = "https://github.com/Ro5hi/coffee_break"
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
|
23
|
+
spec.bindir = "bin"
|
24
|
+
spec.post_install_message = "Thank you for installing coffeebreak!"
|
25
|
+
spec.executables << 'coffee_time'
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
|
28
|
+
spec.add_dependency "nokogiri"
|
29
|
+
spec.add_dependency "open-uri"
|
30
|
+
|
31
|
+
end
|
data/lib/beans.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'pry'
|
2
|
+
|
3
|
+
class CoffeeBreak::Beans
|
4
|
+
|
5
|
+
# Display collection of coffee with corresponding attributes
|
6
|
+
|
7
|
+
attr_accessor :name, :label, :price, :details
|
8
|
+
|
9
|
+
@@all = []
|
10
|
+
|
11
|
+
def initialize(name, label, price, details)
|
12
|
+
@name = name
|
13
|
+
@label = label
|
14
|
+
@price = price
|
15
|
+
@details = details
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.all
|
19
|
+
@@all
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
data/lib/cli.rb
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
require_relative "./scraper.rb"
|
2
|
+
require_relative "./scraper2.rb"
|
3
|
+
|
4
|
+
module CoffeeBreak
|
5
|
+
class CLI
|
6
|
+
|
7
|
+
# Greet the user, runs CLI program
|
8
|
+
|
9
|
+
def run
|
10
|
+
system("clear") # Clears terminal before starting CLI program
|
11
|
+
loading_message
|
12
|
+
|
13
|
+
Scraper.new.scrape
|
14
|
+
Scraper_2.new.scrape_second_page
|
15
|
+
|
16
|
+
greeting
|
17
|
+
while menu != 'exit' # Terminal stays open unless user ends program
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def loading_message
|
23
|
+
puts "Brewing coffee..." # Loading message before program starts
|
24
|
+
puts "Grabbing favourite mug..."
|
25
|
+
puts "Pouring into the mug..."
|
26
|
+
puts " "
|
27
|
+
puts "*slurps*"
|
28
|
+
puts " "
|
29
|
+
puts "+10 Stamina, +10 Charisma, +10 Vitality "
|
30
|
+
puts " "
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
def greeting
|
35
|
+
puts "Welcome to PlayerOneCoffee! Spill the beans, what would you like?"
|
36
|
+
puts "☕️"
|
37
|
+
puts "Enter the number you'd like to know more about."
|
38
|
+
puts "Or type exit to stop the program."
|
39
|
+
puts " "
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
def exit_program
|
44
|
+
puts " "
|
45
|
+
puts "Thanks for stopping by. Until next time!"
|
46
|
+
puts " "
|
47
|
+
exit
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
def menu
|
52
|
+
list_options
|
53
|
+
input = gets.strip.downcase
|
54
|
+
|
55
|
+
if input == "i"
|
56
|
+
puts " "
|
57
|
+
# Blank space to show below if user makes valid.
|
58
|
+
|
59
|
+
elsif input != "exit"
|
60
|
+
i = Integer(input , exception: false)
|
61
|
+
# Parsed input to raise exception when not false
|
62
|
+
if !i.nil?
|
63
|
+
puts i
|
64
|
+
# Prints number user entered.
|
65
|
+
display_coffee(i-1)
|
66
|
+
# Count starts at 0 for the computer, 1 for the user.
|
67
|
+
display_again
|
68
|
+
|
69
|
+
else # Raises argument if input is wrong
|
70
|
+
puts " "
|
71
|
+
puts "Oops! Please try again."
|
72
|
+
puts " "
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
76
|
+
input # User prompted to give input.
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def list_options
|
82
|
+
CoffeeBreak::Beans.all.each_with_index do |product, index|
|
83
|
+
# Products are listed in numerical order with product name.
|
84
|
+
puts "#{index+1} #{product.name}"
|
85
|
+
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def display_coffee(index)
|
90
|
+
puts " "
|
91
|
+
puts "You chose:"
|
92
|
+
puts " "
|
93
|
+
puts "#{CoffeeBreak::Beans.all[index].name}"
|
94
|
+
puts " "
|
95
|
+
puts "#{CoffeeBreak::Beans.all[index].label}"
|
96
|
+
puts " "
|
97
|
+
puts "#{CoffeeBreak::Beans.all[index].price}"
|
98
|
+
puts " "
|
99
|
+
puts "#{CoffeeBreak::Beans.all[index].details}"
|
100
|
+
puts " "
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
def display_again
|
105
|
+
puts "Would you like to see the menu again? [y/n]"
|
106
|
+
answer = gets.strip.downcase
|
107
|
+
|
108
|
+
if answer == "y"
|
109
|
+
puts "Here you go!"
|
110
|
+
puts " "
|
111
|
+
puts " "
|
112
|
+
menu
|
113
|
+
|
114
|
+
elsif answer == "n"
|
115
|
+
exit_program
|
116
|
+
else
|
117
|
+
puts " "
|
118
|
+
puts "Uh-oh! Please try again."
|
119
|
+
puts " "
|
120
|
+
|
121
|
+
end
|
122
|
+
end
|
data/lib/coffeebreak.rb
ADDED
data/lib/scraper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'open-uri'
|
3
|
+
|
4
|
+
module CoffeeBreak
|
5
|
+
class Scraper
|
6
|
+
|
7
|
+
def scrape
|
8
|
+
doc = Nokogiri::HTML(URI.open("https://playeronecoffee.com/collections/all-coffee/"))
|
9
|
+
|
10
|
+
doc.css(".grid-view-item").each do |tag| # Access each tag from below.
|
11
|
+
|
12
|
+
name = tag.css(".grid-view-item__title").text.upcase # Text in UPPERCASE letters.
|
13
|
+
label = tag.css("div.grid-view-item__level span.label").text.upcase # CSS Selector searches document, looking for desired Div classes.
|
14
|
+
price = tag.css("div.grid-view-item__meta span.product-price__price").text # Displays price per specific product.
|
15
|
+
link = "https://playeronecoffee.com"+ tag.css("a.grid-view-item__link")[0][:href] # Grabs href to iterate through product links.
|
16
|
+
details = Nokogiri::HTML(URI.open(link)).css("div.product-single__description p").text # Opens product link to provide details.
|
17
|
+
|
18
|
+
product = Beans.new(name, label, price, details)
|
19
|
+
# Puts all scraped data tags to Beans format.
|
20
|
+
|
21
|
+
Beans.all << product
|
22
|
+
# Stores scraped data onto Beans class.
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
data/lib/scraper2.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'open-uri'
|
3
|
+
|
4
|
+
module CoffeeBreak
|
5
|
+
class Scraper_2
|
6
|
+
|
7
|
+
# Grabs additional products and info from the second page in the url.
|
8
|
+
|
9
|
+
def scrape_second_page
|
10
|
+
doc = Nokogiri::HTML(URI.open("https://playeronecoffee.com/collections/all-coffee?page=2"))
|
11
|
+
|
12
|
+
doc.css(".grid-view-item").each do |tag|
|
13
|
+
|
14
|
+
name = tag.css(".grid-view-item__title").text.upcase
|
15
|
+
label = tag.css("div.grid-view-item__level span.label").text.upcase
|
16
|
+
price = tag.css("div.grid-view-item__meta span.product-price__price").text
|
17
|
+
link = "https://playeronecoffee.com"+ tag.css("a.grid-view-item__link")[0][:href]
|
18
|
+
details = Nokogiri::HTML(URI.open(link)).css("div.product-single__description p").text
|
19
|
+
|
20
|
+
product = Beans.new(name, label, price, details)
|
21
|
+
|
22
|
+
Beans.all << product
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
data/lib/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: coffeebreak
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shirlen Detablan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-07-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: open-uri
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Available products will display their roast type, price, and description.
|
42
|
+
email:
|
43
|
+
- slen.detablan@gmail.com
|
44
|
+
executables:
|
45
|
+
- coffee_time
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- CODE_OF_CONDUCT.md
|
51
|
+
- Gemfile
|
52
|
+
- LICENSE.txt
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- bin/coffee_time
|
56
|
+
- bin/console
|
57
|
+
- bin/setup
|
58
|
+
- coffeebreak.gemspec
|
59
|
+
- lib/beans.rb
|
60
|
+
- lib/cli.rb
|
61
|
+
- lib/coffeebreak.rb
|
62
|
+
- lib/scraper.rb
|
63
|
+
- lib/scraper2.rb
|
64
|
+
- lib/version.rb
|
65
|
+
homepage: https://github.com/Ro5hi/coffee_break
|
66
|
+
licenses:
|
67
|
+
- MIT
|
68
|
+
metadata:
|
69
|
+
homepage_uri: https://github.com/Ro5hi/coffee_break
|
70
|
+
source_code_uri: https://github.com/Ro5hi/coffee_break
|
71
|
+
post_install_message: Thank you for installing coffeebreak!
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubygems_version: 3.1.2
|
87
|
+
signing_key:
|
88
|
+
specification_version: 4
|
89
|
+
summary: View coffee products on PlayerOneCoffee.
|
90
|
+
test_files: []
|