beanbox 0.1.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1c2e38a8fa915e06af84e7f3e68840abdc8e81b1
4
+ data.tar.gz: 7dd33736ce8da4c4e29678a22ad872d80ce1235b
5
+ SHA512:
6
+ metadata.gz: ea2b76ff46ea34425dc4e856ab12bde74347b0fcb861b41a8224b9c8e221de46b6750d43612ed884a063c4d39a5784c026930e254782012dd1d6a1315c21758a
7
+ data.tar.gz: 75dfa78e41fd53bafafcb35c1ca4d0708958b2308a897fce3507235733c22c0ef1125b8f329b37287bb3ed3e34ce22f1ecb015264b867061656c35a26fe07d3c
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /Gemfile.lock/
@@ -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 aspenjames@tqca.org. 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 [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in beanbox.gemspec
6
+ gemspec
@@ -0,0 +1,30 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ beanbox (0.1.1)
5
+ nokogiri
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ coderay (1.1.2)
11
+ method_source (0.9.0)
12
+ mini_portile2 (2.3.0)
13
+ nokogiri (1.8.2)
14
+ mini_portile2 (~> 2.3.0)
15
+ pry (0.11.3)
16
+ coderay (~> 1.1.0)
17
+ method_source (~> 0.9.0)
18
+ rake (10.4.2)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ beanbox!
25
+ bundler (~> 1.16)
26
+ pry
27
+ rake (~> 10.0)
28
+
29
+ BUNDLED WITH
30
+ 1.16.1
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 TODO: Write your name
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.
@@ -0,0 +1,41 @@
1
+ # Beanbox
2
+
3
+ Welcome! This gem provides information on Seattle's top selling coffees on Beanbox.co via a simple and easy-to-use command-line interface.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'beanbox'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install beanbox
20
+
21
+ ## Usage
22
+
23
+ Simply run the command `beanbox` in your terminal to see a list of the top four best selling coffees on Beanbox.co as well as their price. Type in a coffee's list number and press enter to see more detailed information about that specific coffee.
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/[USERNAME]/beanbox. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
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 Beanbox project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/beanbox/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,38 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "beanbox/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "beanbox"
8
+ spec.version = Beanbox::VERSION
9
+ spec.authors = ["Aspen James"]
10
+ spec.email = ["aspenjames@tqca.org"]
11
+
12
+ spec.summary = "Shows Bean Box's top selling coffees"
13
+ spec.description = "Lists Seattle's top selling coffees on beanbox.co with the option to view further information via a command-line interface."
14
+ spec.homepage = "https://github.com/AspenJames/beanbox"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against " \
23
+ # "public gem pushes."
24
+ # end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "bin"
30
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.16"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "pry", "~> 0.11"
36
+ spec.add_runtime_dependency "nokogiri", "~>1.8"
37
+
38
+ end
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "beanbox"
5
+
6
+ Beanbox::CLI.new.run
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "beanbox"
5
+
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,8 @@
1
+ require "beanbox/version"
2
+ require_relative "./beanbox/cli"
3
+ require_relative "./beanbox/coffee"
4
+ require_relative "./beanbox/scraper"
5
+
6
+ module Beanbox
7
+ # Your code goes here...
8
+ end
@@ -0,0 +1,76 @@
1
+ require 'pry'
2
+ class Beanbox::CLI
3
+
4
+ def initialize
5
+ Beanbox::Coffee.reset!
6
+ end
7
+
8
+ def run
9
+ Beanbox::Scraper.new("https://beanbox.co/coffee").scrape
10
+ self.list_coffees
11
+ self.list_menu
12
+ end
13
+
14
+ def list_coffees
15
+ puts "Hello! Today's top selling coffees are: "
16
+ Beanbox::Coffee.all.each_with_index do |c, i|
17
+ puts "#{i + 1}. #{c.name} roasted by #{c.roaster} at #{c.price}"
18
+ puts
19
+ end
20
+ end
21
+
22
+ def list_detail(coffee)
23
+ Beanbox::Scraper.new(coffee.url).scrape_detail(coffee)
24
+ puts
25
+ puts "#{coffee.name} roasted by #{coffee.roaster}"
26
+ puts "Type: #{coffee.type}"
27
+ puts "Roast level: #{coffee.roast_level}"
28
+ puts "Price: #{coffee.price}"
29
+ puts
30
+ puts "#{coffee.description}"
31
+ puts
32
+ puts 'Enter "list" to return the menu or "exit!"'
33
+ input = nil
34
+ until input == "exit!"
35
+ input = gets.chomp
36
+ if input == "list"
37
+ self.list_coffees
38
+ self.list_menu
39
+ break
40
+ elsif input == "exit!"
41
+ exit
42
+ else
43
+ puts "I didn't quite get that..."
44
+ self.list_menu
45
+ end
46
+ end
47
+ end
48
+
49
+ def list_menu
50
+ puts 'Select a number for more information, "exit!", or "list" to return to the menu'
51
+ input = nil
52
+ until input == "exit!"
53
+ input = gets.chomp
54
+ case input
55
+ when "1"
56
+ self.list_detail(Beanbox::Coffee.all[0])
57
+ when "2"
58
+ self.list_detail(Beanbox::Coffee.all[1])
59
+ when "3"
60
+ self.list_detail(Beanbox::Coffee.all[2])
61
+ when "4"
62
+ self.list_detail(Beanbox::Coffee.all[3])
63
+ when "list"
64
+ self.list_coffees
65
+ self.list_menu
66
+ when "exit!"
67
+ exit
68
+ else
69
+ puts "I didn't quite get that..."
70
+ self.list_menu
71
+ end
72
+ end
73
+ end
74
+
75
+
76
+ end
@@ -0,0 +1,16 @@
1
+ class Beanbox::Coffee
2
+ attr_accessor :name, :roaster, :price, :url, :type, :roast_level, :description
3
+ @@all = []
4
+
5
+ def initialize
6
+ @@all << self
7
+ end
8
+
9
+ def self.all
10
+ @@all
11
+ end
12
+
13
+ def self.reset!
14
+ @@all = []
15
+ end
16
+ end
@@ -0,0 +1,35 @@
1
+ require 'nokogiri'
2
+ require 'open-uri'
3
+ require 'pry'
4
+
5
+ class Beanbox::Scraper
6
+ attr_accessor :URL_path, :doc, :results
7
+
8
+ def initialize(u)
9
+ @URL_path = u
10
+ @results = []
11
+ end
12
+
13
+ def scrape
14
+ @doc = Nokogiri::HTML(open(@URL_path))
15
+ @doc.css("div.twelve.columns.center.pad-top").first.css("div.roast-list").each do |element|
16
+ coffee = Beanbox::Coffee.new
17
+ coffee.name = element.css("h2").text
18
+ # This next line normalizes the name, which is returned in all caps
19
+ coffee.name = coffee.name.split(" ").collect{|n| n.capitalize}.join(" ")
20
+ coffee.roaster = element.css("h3.roast-item-roaster a").text
21
+ coffee.price = element.css("h4.roast-item-price").text.split("\n")[1]
22
+ coffee.url = element.css("a").attribute("href").value
23
+ self.results << coffee # add each coffee to @results
24
+ end
25
+
26
+ self.results
27
+ end
28
+
29
+ def scrape_detail(coffee)
30
+ @doc = Nokogiri::HTML(open(@URL_path))
31
+ coffee.description = @doc.css("div.bb p").text.strip
32
+ coffee.type = @doc.css("div.centered-mobile span.rt a")[1].text
33
+ coffee.roast_level = @doc.css("div.centered-mobile span.rt a")[0].text
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ module Beanbox
2
+ VERSION = "0.1.1"
3
+ end
data/spec.md ADDED
@@ -0,0 +1,9 @@
1
+ # Specifications for the CLI Assessment
2
+
3
+ Specs:
4
+ - [x] Have a CLI for interfacing with the application
5
+ - Users navigate a CLI interface laid out in Beanbox::CLI
6
+ - [x] Pull data from an external source
7
+ - Beanbox::Scraper scrapes beanbox.co for information
8
+ - [x] Implement both list and detail views
9
+ - Selecting a menu item from the main menu will supply further information on that specifc coffee
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: beanbox
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Aspen James
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-03-30 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: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
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
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.11'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: nokogiri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.8'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.8'
69
+ description: Lists Seattle's top selling coffees on beanbox.co with the option to
70
+ view further information via a command-line interface.
71
+ email:
72
+ - aspenjames@tqca.org
73
+ executables:
74
+ - beanbox
75
+ - console
76
+ - setup
77
+ extensions: []
78
+ extra_rdoc_files: []
79
+ files:
80
+ - ".gitignore"
81
+ - CODE_OF_CONDUCT.md
82
+ - Gemfile
83
+ - Gemfile.lock
84
+ - LICENSE.txt
85
+ - README.md
86
+ - Rakefile
87
+ - beanbox.gemspec
88
+ - bin/beanbox
89
+ - bin/console
90
+ - bin/setup
91
+ - lib/beanbox.rb
92
+ - lib/beanbox/cli.rb
93
+ - lib/beanbox/coffee.rb
94
+ - lib/beanbox/scraper.rb
95
+ - lib/beanbox/version.rb
96
+ - spec.md
97
+ homepage: https://github.com/AspenJames/beanbox
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.6.14
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: Shows Bean Box's top selling coffees
121
+ test_files: []