compare_supermarkets 0.1.12 → 0.2.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 +4 -4
- data/config/environment.rb +1 -0
- data/lib/compare_supermarkets/cli.rb +2 -1
- data/lib/compare_supermarkets/product.rb +10 -31
- data/lib/compare_supermarkets/scraper.rb +4 -2
- data/lib/compare_supermarkets/supermarket.rb +41 -0
- data/lib/compare_supermarkets/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f7490e1c56c5edabeb3ec9606053b7187c709f8082c1e57e632414a1f459d0f
|
4
|
+
data.tar.gz: 18c85e7f34f0ef20653f3f7b045b99a3cf06a196e58b95bcfa29932dc9fd532c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93cdab62149c48bc0c26bfa010f9f1af0067ef3e2f2a0e0dab02e9b26ea99758e1cbb080e6db51d7e249296437206d8f8e5513741532de5d48d031d5e035f5d9
|
7
|
+
data.tar.gz: 264d1fe7787fb13b2d78a5ee638e4ecac23d87c0df7ef59f864c654b2aebb9c3ccdd1fe542472c4f3026bd1984c69f84b2254d89b3587c8f9ccf312db5724697
|
data/config/environment.rb
CHANGED
@@ -9,5 +9,6 @@ require_relative '../lib/compare_supermarkets/scraper'
|
|
9
9
|
require_relative '../lib/compare_supermarkets/product'
|
10
10
|
require_relative '../lib/compare_supermarkets/cli'
|
11
11
|
require_relative '../lib/compare_supermarkets/version'
|
12
|
+
require_relative '../lib/compare_supermarkets/supermarket'
|
12
13
|
|
13
14
|
Watir.default_timeout = 0
|
@@ -200,6 +200,7 @@ class CompareSupermarkets::CLI
|
|
200
200
|
how_to_display
|
201
201
|
elsif input == "2"
|
202
202
|
CompareSupermarkets::Product.clear_all
|
203
|
+
CompareSupermarkets::Supermarket.clear_all
|
203
204
|
start
|
204
205
|
elsif input == ""
|
205
206
|
invalid_input
|
@@ -263,7 +264,7 @@ class CompareSupermarkets::CLI
|
|
263
264
|
def print_items(choice, direction)
|
264
265
|
direction == "asc" ? choice = choice : choice = choice.reverse
|
265
266
|
choice.each do |item|
|
266
|
-
p "Supermarket: #{item.supermarket}"
|
267
|
+
p "Supermarket: #{item.supermarket.name}"
|
267
268
|
p "Item name: #{item.name}"
|
268
269
|
p "Item price: $#{item.dollar_value}.#{item.cent_value}"
|
269
270
|
p "Item unit size: #{item.unit_size}"
|
@@ -1,10 +1,7 @@
|
|
1
1
|
class CompareSupermarkets::Product
|
2
|
-
|
3
|
-
attr_reader :supermarket, :name, :price, :unit_size, :url, :dollar_value, :cent_value
|
2
|
+
attr_accessor :supermarket, :name, :price, :unit_size, :url, :dollar_value, :cent_value
|
4
3
|
|
5
4
|
@@all = []
|
6
|
-
@@coles_all = []
|
7
|
-
@@woolworths_all = []
|
8
5
|
|
9
6
|
def initialize (supermarket = nil, name = nil, price=nil, unit_size = nil, url = nil, dollar_value=nil, cent_value=nil)
|
10
7
|
@supermarket = supermarket
|
@@ -13,45 +10,25 @@ class CompareSupermarkets::Product
|
|
13
10
|
@unit_size = unit_size
|
14
11
|
@dollar_value = dollar_value
|
15
12
|
@cent_value = cent_value
|
16
|
-
@url = @supermarket == "Coles" ? "https://shop.coles.com.au#{url}" : "https://www.woolworths.com.au#{url}"
|
13
|
+
@url = @supermarket.name == "Coles" ? "https://shop.coles.com.au#{url}" : "https://www.woolworths.com.au#{url}"
|
17
14
|
@@all << self
|
18
|
-
if @supermarket == "Coles"
|
19
|
-
@@coles_all << self
|
20
|
-
else
|
21
|
-
@@woolworths_all << self
|
22
|
-
end
|
23
15
|
end
|
24
16
|
|
25
17
|
def self.all
|
26
|
-
|
18
|
+
@@all
|
27
19
|
end
|
28
20
|
|
29
21
|
def self.count
|
30
22
|
@@all.count
|
31
23
|
end
|
32
24
|
|
33
|
-
def
|
34
|
-
|
35
|
-
product.css(".product-name").text,
|
36
|
-
product.css(".package-price").text.delete_prefix('$').gsub('per', '/'),
|
37
|
-
product.css(".package-size.accessibility-inline").text,
|
38
|
-
product.css(".product-image-link").attribute('href'),
|
39
|
-
product.css(".dollar-value").text,
|
40
|
-
product.css(".cent-value").text.delete_prefix('.'))
|
25
|
+
def supermarket_name
|
26
|
+
self.supermarket ? self.supermarket.name : nil
|
41
27
|
end
|
42
28
|
|
43
|
-
def self.woolworths_new_from_search(product)
|
44
|
-
product_to_compare = self.new("Woolworths",
|
45
|
-
product.css(".shelfProductTile-descriptionLink").text,
|
46
|
-
product.css(".shelfProductTile-cupPrice.ng-star-inserted").text.delete_prefix(' $').chomp(" "),
|
47
|
-
product.css(".shelfProductTile-descriptionLink").text.split(" ").last,
|
48
|
-
product.css(".shelfProductTile-descriptionLink").attribute('href').value,
|
49
|
-
product.css(".price-dollars").text,
|
50
|
-
product.css(".price-cents").text)
|
51
|
-
end
|
52
29
|
|
53
30
|
def self.all_items_sorted_by_price
|
54
|
-
sorted =
|
31
|
+
sorted = self.all.sort_by! do |s|
|
55
32
|
price_to_sort = s.dollar_value + '.' + s.cent_value
|
56
33
|
price_to_sort.to_f
|
57
34
|
end
|
@@ -62,14 +39,16 @@ class CompareSupermarkets::Product
|
|
62
39
|
end
|
63
40
|
|
64
41
|
def self.coles_sorted_by_price
|
65
|
-
|
42
|
+
coles_items = self.all.select{|product| product.supermarket_name == "Coles"}
|
43
|
+
coles_items.sort_by! do |s|
|
66
44
|
price_to_sort = s.dollar_value + '.' + s.cent_value
|
67
45
|
price_to_sort.to_f
|
68
46
|
end
|
69
47
|
end
|
70
48
|
|
71
49
|
def self.woolworths_sorted_by_price
|
72
|
-
|
50
|
+
woolworths_items = self.all.select{|product| product.supermarket_name == "Woolworths"}
|
51
|
+
woolworths_items.sort_by! do |s|
|
73
52
|
price_to_sort = s.dollar_value + '.' + s.cent_value
|
74
53
|
price_to_sort.to_f
|
75
54
|
end
|
@@ -27,7 +27,8 @@ class CompareSupermarkets::Scraper
|
|
27
27
|
all_coles_products = coles_products.css(".product")
|
28
28
|
all_coles_products.each do |product|
|
29
29
|
if product.css(".product-name").text != ""
|
30
|
-
CompareSupermarkets::
|
30
|
+
coles = CompareSupermarkets::Supermarket.new("Coles")
|
31
|
+
coles.add_product(product)
|
31
32
|
end
|
32
33
|
end
|
33
34
|
ensure
|
@@ -48,7 +49,8 @@ class CompareSupermarkets::Scraper
|
|
48
49
|
woolworths_all_products.each do |product|
|
49
50
|
if product.css(".shelfProductTile-descriptionLink").text != ""
|
50
51
|
if product.css(".unavailableSection.width-full.ng-star-inserted").empty?
|
51
|
-
CompareSupermarkets::
|
52
|
+
woolworths = CompareSupermarkets::Supermarket.new("Woolworths")
|
53
|
+
woolworths.add_product(product)
|
52
54
|
end
|
53
55
|
end
|
54
56
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
class CompareSupermarkets::Supermarket
|
2
|
+
attr_accessor :name
|
3
|
+
|
4
|
+
@@all = []
|
5
|
+
|
6
|
+
def initialize(name=nil)
|
7
|
+
@name = name
|
8
|
+
@@all << self
|
9
|
+
@products = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def add_product(product)
|
13
|
+
if self.name == "Coles"
|
14
|
+
new_product = CompareSupermarkets::Product.new(self,
|
15
|
+
product.css(".product-name").text,
|
16
|
+
product.css(".package-price").text.delete_prefix('$').gsub('per', '/'),
|
17
|
+
product.css(".package-size.accessibility-inline").text,
|
18
|
+
product.css(".product-image-link").attribute('href'),
|
19
|
+
product.css(".dollar-value").text,
|
20
|
+
product.css(".cent-value").text.delete_prefix('.'))
|
21
|
+
else
|
22
|
+
new_product = CompareSupermarkets::Product.new(self,
|
23
|
+
product.css(".shelfProductTile-descriptionLink").text,
|
24
|
+
product.css(".shelfProductTile-cupPrice.ng-star-inserted").text.delete_prefix(' $').chomp(" "),
|
25
|
+
product.css(".shelfProductTile-descriptionLink").text.split(" ").last,
|
26
|
+
product.css(".shelfProductTile-descriptionLink").attribute('href').value,
|
27
|
+
product.css(".price-dollars").text,
|
28
|
+
product.css(".price-cents").text)
|
29
|
+
end
|
30
|
+
@products << new_product
|
31
|
+
end
|
32
|
+
|
33
|
+
def products
|
34
|
+
CompareSupermarkets::Product.all.select{|product| product.supermarket == self}
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.clear_all
|
38
|
+
@@all.clear
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: compare_supermarkets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Berger Howes
|
@@ -125,6 +125,7 @@ files:
|
|
125
125
|
- lib/compare_supermarkets/cli.rb
|
126
126
|
- lib/compare_supermarkets/product.rb
|
127
127
|
- lib/compare_supermarkets/scraper.rb
|
128
|
+
- lib/compare_supermarkets/supermarket.rb
|
128
129
|
- lib/compare_supermarkets/version.rb
|
129
130
|
homepage: http://rubygems.org/gems/compare_supermarkets
|
130
131
|
licenses:
|