coffeebreak 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f658c012f3f01d6a7bc3f0150fc0a607bf2447840e525b9abaae4a4f03656d5
4
- data.tar.gz: ff13fe7744ac797fc8a3f12abb2e70c6e72a851753c1585db5a611bab629c0c0
3
+ metadata.gz: cb3fd9e88e5939a78f2cb43a60ba50b7ac2e04aab1c63a29f4d7eed727077236
4
+ data.tar.gz: 39c57c76437976c2b47d77e75c1605b6ccccdf11baa222351e1dd20d4ccd2cf2
5
5
  SHA512:
6
- metadata.gz: b014fba445925d12925bdc950475049967f474d67474ca8deb160b3fd0d0eeb6b4c104965ab43c1c1ff7faf2fdd7f24f302cd13850453825f1ea42808178fd5e
7
- data.tar.gz: e4aff878840ee7f4bab211fb7dbd25dbbc10b4e38d33dee98d8cd29b778b39daedada911aad608c71fd88a5488620d19f6caa4e50341316453e0bad9392f390a
6
+ metadata.gz: 82e9f93d8ddceb3296c143e13aa07ae6929a0610e9f0cfb714102aee3a8c06f16cad6e4424c33340fc27da42ea87113a40ab36567286406ce3d2ce5437eed944
7
+ data.tar.gz: e4bbc40f1a37b82731366cf7a310f1ae0f1a3075e236532a63b4ab20345a4c7cd2114d3b46024ea6aa80619b2c450338653acdf25fdd1fea2a27d95510f80b11
Binary file
@@ -4,15 +4,19 @@ class CoffeeBreak::Beans
4
4
 
5
5
  # Display collection of coffee with corresponding attributes
6
6
 
7
- attr_accessor :name, :label, :price, :details
7
+ attr_accessor :name, :label, :price, :details, :link
8
8
 
9
- @@all = []
9
+ # Stores every instance of Beans and anything collected from scrape methods will display in CLI.
10
10
 
11
- def initialize(name, label, price, details)
11
+ @@all = []
12
+
13
+ def initialize(name, label, price, link, details=nil)
12
14
  @name = name
13
15
  @label = label
14
16
  @price = price
15
17
  @details = details
18
+ @link = link
19
+ @@all << self
16
20
  end
17
21
 
18
22
  def self.all
data/lib/cli.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require_relative "./scraper.rb"
2
- require_relative "./scraper2.rb"
3
2
 
4
3
  module CoffeeBreak
5
4
  class CLI
@@ -10,11 +9,10 @@ module CoffeeBreak
10
9
  system("clear") # Clears terminal before starting CLI program
11
10
  loading_message
12
11
 
13
- Scraper.new.scrape
14
- Scraper_2.new.scrape_second_page
12
+ Scraper.new.scrape # Displays product list from 1st page.
15
13
 
16
14
  greeting
17
- while menu != 'exit' # Terminal stays open unless user ends program
15
+ while menu != 'exit' # Checks to see if user will exit program. Otherwise, terminal stays open to show menu.
18
16
 
19
17
  end
20
18
  end
@@ -52,54 +50,58 @@ module CoffeeBreak
52
50
  list_options
53
51
  input = gets.strip.downcase
54
52
 
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
53
+ if input == "i"
70
54
  puts " "
71
- puts "Oops! Please try again."
72
- puts " "
55
+ # Blank space to show below if user makes valid.
56
+
57
+ elsif input != "exit"
58
+ i = Integer(input , exception: false)
59
+ # Parsed input to raise exception when not false
60
+ puts " "
61
+ if i.between?(1,17)
62
+ puts i
63
+ # Prints number user entered.
64
+ display_coffee(i-1)
65
+ # Count starts at 0 for the computer, 1 for the user.
66
+ display_again
67
+ else
68
+ # Raises argument if input is wrong
69
+ puts " "
70
+ puts "Oops! Please try again."
71
+ puts " "
73
72
 
73
+ end
74
+ end
75
+ input # User prompted to give input.
74
76
  end
75
- end
76
- input # User prompted to give input.
77
- end
78
- end
79
- end
77
+ end
78
+ end
80
79
 
81
80
  def list_options
82
81
  CoffeeBreak::Beans.all.each_with_index do |product, index|
83
82
  # Products are listed in numerical order with product name.
84
83
  puts "#{index+1} #{product.name}"
85
-
84
+ # Data obtained from scrape method displays the name of "product" by order.
86
85
  end
87
86
  end
88
87
 
89
88
  def display_coffee(index)
89
+ bean = CoffeeBreak::Beans.all[index]
90
+ CoffeeBreak::Scraper.new.scrape_details(bean)
91
+
90
92
  puts " "
91
93
  puts "You chose:"
92
94
  puts " "
93
- puts "#{CoffeeBreak::Beans.all[index].name}"
95
+ puts "#{bean.name}"
94
96
  puts " "
95
- puts "#{CoffeeBreak::Beans.all[index].label}"
97
+ puts "#{bean.label}"
96
98
  puts " "
97
- puts "#{CoffeeBreak::Beans.all[index].price}"
99
+ puts "#{bean.price}"
98
100
  puts " "
99
- puts "#{CoffeeBreak::Beans.all[index].details}"
101
+ puts "#{bean.details}"
100
102
  puts " "
101
103
 
102
- end
104
+ end
103
105
 
104
106
  def display_again
105
107
  puts "Would you like to see the menu again? [y/n]"
@@ -111,12 +113,13 @@ module CoffeeBreak
111
113
  puts " "
112
114
  menu
113
115
 
114
- elsif answer == "n"
116
+ elsif answer == "n" || answer == "exit"
115
117
  exit_program
116
118
  else
117
119
  puts " "
118
120
  puts "Uh-oh! Please try again."
119
121
  puts " "
120
122
 
121
- end
122
- end
123
+ end
124
+
125
+ end
@@ -7,22 +7,47 @@ module CoffeeBreak
7
7
  def scrape
8
8
  doc = Nokogiri::HTML(URI.open("https://playeronecoffee.com/collections/all-coffee/"))
9
9
 
10
- doc.css(".grid-view-item").each do |tag| # Access each tag from below.
10
+ doc.css(".grid-view-item").each do |tag| # Filter through the page to access specific elements.
11
11
 
12
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.
13
+ label = tag.css("div.grid-view-item__level span.label").text.upcase # CSS Selector searches document, looking for desired Div class LABEL.
14
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.
15
+ link = "https://playeronecoffee.com"+ tag.css("a.grid-view-item__link")[0][:href] # Grabs href to obtain desired product links.
16
+ # details = Nokogiri::HTML(URI.open(link)).css("div.product-single__description p").text # Opens link, access element, and provide details.
17
17
 
18
- product = Beans.new(name, label, price, details)
19
- # Puts all scraped data tags to Beans format.
18
+ product = Beans.new(name, label, price, link)
19
+ # Product variable used to store all scraped data from tags onto argument format for Beans.
20
20
 
21
- Beans.all << product
22
- # Stores scraped data onto Beans class.
21
+ # Beans.all << product
22
+ # Everything about "product" will be stored onto the object, Beans.
23
23
 
24
24
  end
25
+ self.scrape_second_page
25
26
  end
27
+
28
+ def scrape_details(product)
29
+ details = Nokogiri::HTML(URI.open(product.link)).css("div.product-single__description p").text
30
+ product.details = details
31
+ end
32
+
33
+ def scrape_second_page
34
+
35
+ doc = Nokogiri::HTML(URI.open("https://playeronecoffee.com/collections/all-coffee?page=2"))
36
+
37
+ doc.css(".grid-view-item").each do |tag|
38
+
39
+ name = tag.css(".grid-view-item__title").text.upcase
40
+ label = tag.css("div.grid-view-item__level span.label").text.upcase
41
+ price = tag.css("div.grid-view-item__meta span.product-price__price").text
42
+ link = "https://playeronecoffee.com"+ tag.css("a.grid-view-item__link")[0][:href]
43
+ # details = Nokogiri::HTML(URI.open(link)).css("div.product-single__description p").text
44
+
45
+ product = Beans.new(name, label, price, link)
46
+
47
+ # Beans.all << product
48
+
49
+ end
50
+ end
26
51
 
27
52
  end
28
53
  end
@@ -1,3 +1,3 @@
1
1
  module CoffeeBreak
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coffeebreak
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shirlen Detablan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-15 00:00:00.000000000 Z
11
+ date: 2020-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -55,12 +55,12 @@ files:
55
55
  - bin/coffee_time
56
56
  - bin/console
57
57
  - bin/setup
58
+ - coffeebreak-0.1.0.gem
58
59
  - coffeebreak.gemspec
59
60
  - lib/beans.rb
60
61
  - lib/cli.rb
61
62
  - lib/coffeebreak.rb
62
63
  - lib/scraper.rb
63
- - lib/scraper2.rb
64
64
  - lib/version.rb
65
65
  homepage: https://github.com/Ro5hi/coffee_break
66
66
  licenses:
@@ -1,28 +0,0 @@
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