beanbox 0.1.2 → 0.1.4

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
  SHA1:
3
- metadata.gz: c63252d6973059c649f208b3fbad1d7ed74c8d9e
4
- data.tar.gz: de6304da49c14e30a83c73a883aeefdebaf5503c
3
+ metadata.gz: a59f7d11c09d08cc3533d468b2c607321662c39a
4
+ data.tar.gz: acad27f2246b16c3e35b3a38d8baba9b3552b79c
5
5
  SHA512:
6
- metadata.gz: 3a10b85b0fd9d9325115946303c0c5017cae9f7326f0e83edf8a92e4183c5a6213debd1f68acb51f98f98bc9e2702015a38ff3b8478da92656f486992986064c
7
- data.tar.gz: 03175ce62039b203e97961ddf9e2c9b58199ab5fe1bc8b06beb1de6829cf58b7e9c6e40d796f879fc2f7eb3299ab859d53badf44cf7b1538b22853831ac31cd4
6
+ metadata.gz: e127453df390549e67c6021d45824b4564dd443b478d117c6acf42dd4cd3675f7b11e79ac4605fba0a6df67f0f2bffd168218459734c5eeabfe4bcad99019648
7
+ data.tar.gz: a77d7fd01a99f8024e2cb98ea5ad3f10368ca07e488216bdad4eec05266a709453b028f1ab47230e9f319551b255f8ab89c33e87278a536439b8e3b2b089c02b
data/README.md CHANGED
@@ -18,9 +18,11 @@ Or install it yourself as:
18
18
 
19
19
  $ gem install beanbox
20
20
 
21
+ This gem depends on Ruby version 2.3.3. You may need to install [rvm](https://rvm.io) if you have a different version of Ruby installed. Run `rvm install 2.3.3` and `rvm use 2.3.3`, then `bundle install` again.
22
+
21
23
  ## Usage
22
24
 
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.
25
+ 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
26
 
25
27
  ## Development
26
28
 
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.bindir = "bin"
30
30
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
31
31
  spec.require_paths = ["lib"]
32
- spec.required_ruby_version = '~> 2.3'
32
+ spec.required_ruby_version = '~> 2.3.3'
33
33
 
34
34
  spec.add_development_dependency "bundler", "~> 1.16"
35
35
  spec.add_development_dependency "rake", "~> 10.0"
@@ -1,12 +1,14 @@
1
1
  require 'pry'
2
2
  class Beanbox::CLI
3
+ attr_accessor :scraper
3
4
 
4
5
  def initialize
5
6
  Beanbox::Coffee.reset!
6
7
  end
7
8
 
8
9
  def run
9
- Beanbox::Scraper.new("https://beanbox.co/coffee").scrape
10
+ @scraper = Beanbox::Scraper.new("https://beanbox.co/coffee/best-sellers")
11
+ @scraper.scrape
10
12
  self.list_coffees
11
13
  self.list_menu
12
14
  end
@@ -20,7 +22,7 @@ class Beanbox::CLI
20
22
  end
21
23
 
22
24
  def list_detail(coffee)
23
- Beanbox::Scraper.new(coffee.url).scrape_detail(coffee)
25
+ @scraper.scrape_detail(coffee)
24
26
  puts
25
27
  puts "#{coffee.name} roasted by #{coffee.roaster}"
26
28
  puts "Type: #{coffee.type}"
@@ -60,6 +62,18 @@ class Beanbox::CLI
60
62
  self.list_detail(Beanbox::Coffee.all[2])
61
63
  when "4"
62
64
  self.list_detail(Beanbox::Coffee.all[3])
65
+ when "5"
66
+ self.list_detail(Beanbox::Coffee.all[4])
67
+ when "6"
68
+ self.list_detail(Beanbox::Coffee.all[5])
69
+ when "7"
70
+ self.list_detail(Beanbox::Coffee.all[6])
71
+ when "8"
72
+ self.list_detail(Beanbox::Coffee.all[7])
73
+ when "9"
74
+ self.list_detail(Beanbox::Coffee.all[8])
75
+ when "10"
76
+ self.list_detail(Beanbox::Coffee.all[9])
63
77
  when "list"
64
78
  self.list_coffees
65
79
  self.list_menu
@@ -3,33 +3,56 @@ require 'open-uri'
3
3
  require 'pry'
4
4
 
5
5
  class Beanbox::Scraper
6
- attr_accessor :URL_path, :doc, :results
6
+ attr_accessor :URL_path, :doc, :results, :detail
7
7
 
8
8
  def initialize(u)
9
9
  @URL_path = u
10
10
  @results = []
11
11
  end
12
12
 
13
+
13
14
  def scrape
14
15
  @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
16
+ @doc.css("div.ten.columns.center.results").first.css("div.roast-list").each_with_index do |element, i|
17
+ if ((0..9).to_a.include?(i))
18
+ coffee = Beanbox::Coffee.new
19
+ coffee.name = element.css("h2").text
20
+ # This next line normalizes the name, which is returned in all caps
21
+ coffee.name = coffee.name.split(" ").collect{|n| n.capitalize}.join(" ")
22
+ coffee.roaster = element.css("h3.roast-item-roaster a").text
23
+ coffee.price = element.css("h4.roast-item-price").text.split("\n")[1]
24
+ coffee.url = element.css("a").attribute("href").value
25
+ # binding.pry
26
+ self.results << coffee # add each coffee to @results
27
+ end
24
28
  end
25
29
 
26
30
  self.results
27
31
  end
28
32
 
33
+
34
+ # def scrape
35
+ # @doc = Nokogiri::HTML(open(@URL_path))
36
+ # @doc.css("div.twelve.columns.center.pad-top").first.css("div.roast-list").each do |element|
37
+ # coffee = Beanbox::Coffee.new
38
+ # coffee.name = element.css("h2").text
39
+ # # This next line normalizes the name, which is returned in all caps
40
+ # coffee.name = coffee.name.split(" ").collect{|n| n.capitalize}.join(" ")
41
+ # coffee.roaster = element.css("h3.roast-item-roaster a").text
42
+ # coffee.price = element.css("h4.roast-item-price").text.split("\n")[1]
43
+ # coffee.url = element.css("a").attribute("href").value
44
+ # self.results << coffee # add each coffee to @results
45
+ # end
46
+ #
47
+ # self.results
48
+ # end
49
+
50
+
29
51
  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
52
+ @detail = Nokogiri::HTML(open(coffee.url))
53
+ # binding.pry
54
+ coffee.description = @detail.css("div.bb p").text.strip
55
+ coffee.type = @detail.css("div.centered-mobile span.rt a").first.text
56
+ coffee.roast_level = @detail.css("div.centered-mobile span.rt a").first.text
34
57
  end
35
58
  end
@@ -1,3 +1,3 @@
1
1
  module Beanbox
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beanbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aspen James
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-30 00:00:00.000000000 Z
11
+ date: 2018-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -84,7 +84,6 @@ files:
84
84
  - LICENSE.txt
85
85
  - README.md
86
86
  - Rakefile
87
- - beanbox-0.1.1.gem
88
87
  - beanbox.gemspec
89
88
  - bin/beanbox
90
89
  - bin/console
@@ -107,7 +106,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
107
106
  requirements:
108
107
  - - "~>"
109
108
  - !ruby/object:Gem::Version
110
- version: '2.3'
109
+ version: 2.3.3
111
110
  required_rubygems_version: !ruby/object:Gem::Requirement
112
111
  requirements:
113
112
  - - ">="
Binary file