compare_supermarkets 0.1.9 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 21d751bb1877f2aec5c1b3f80dcf680b41006b4e2be969d0fc31f9d6c1ae390d
4
- data.tar.gz: b0daf658c23f131b73f159af94b50de565e210e6e91b71e69bc495ac1dd1a36f
3
+ metadata.gz: 0f7490e1c56c5edabeb3ec9606053b7187c709f8082c1e57e632414a1f459d0f
4
+ data.tar.gz: 18c85e7f34f0ef20653f3f7b045b99a3cf06a196e58b95bcfa29932dc9fd532c
5
5
  SHA512:
6
- metadata.gz: 94187db55938eaca84e23d48616391e182f64d90d3c148911a68db6de43076c6d7afb108474c77f2e83cb1bf7b8ae7f76374d68108a1c393758ab6774b39f67a
7
- data.tar.gz: cbd9fbb88dfcafb951950ca7b5be1739be62849e2247a739d8d00eb2f1c950733d3a0d8f00f2b5bbcb527ec0dab28d6798cc5926bc40286c5b1abf5f741c3b94
6
+ metadata.gz: 93cdab62149c48bc0c26bfa010f9f1af0067ef3e2f2a0e0dab02e9b26ea99758e1cbb080e6db51d7e249296437206d8f8e5513741532de5d48d031d5e035f5d9
7
+ data.tar.gz: 264d1fe7787fb13b2d78a5ee638e4ecac23d87c0df7ef59f864c654b2aebb9c3ccdd1fe542472c4f3026bd1984c69f84b2254d89b3587c8f9ccf312db5724697
data/bin/setup CHANGED
@@ -3,4 +3,5 @@
3
3
  set -euo pipefail
4
4
  IFS=$'\n\t'
5
5
 
6
- bundle install
6
+ bundle install
7
+ brew install --cask chromedriver #required for watir to work
@@ -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
- attr_writer :price
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
- @all
18
+ @@all
27
19
  end
28
20
 
29
21
  def self.count
30
22
  @@all.count
31
23
  end
32
24
 
33
- def self.coles_new_from_search(product)
34
- product_to_compare = self.new("Coles",
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 = @@all.sort_by! do |s|
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
- @@coles_all.sort_by! do |s|
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
- @@woolworths_all.sort_by! do |s|
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::Product.coles_new_from_search(product)
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::Product.woolworths_new_from_search(product)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CompareSupermarkets
4
- VERSION = "0.1.9"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: compare_supermarkets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Berger Howes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-27 00:00:00.000000000 Z
11
+ date: 2021-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,47 +80,38 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- description: |
84
- Will search Woolworths and Coles online stores for prices based on an input search parameter
85
- # CompareSupermarkets
86
-
87
- Ever wondered 'I wonder if my shampoo is cheaper at Coles or Woolworths...?' ? But can't be
88
- bothered searching both websites and comparing? Well that's what this gem does for you. Simply
89
- install and follow the prompts.
90
-
91
- ## Installation
92
-
93
- Add this line to your application's Gemfile:
94
-
95
- ```ruby
96
- gem 'compare_supermarkets'
97
- ```
98
-
99
- And then execute:
100
-
101
- $ bundle install
102
-
103
- Or install it yourself as:
104
-
105
- $ gem install compare_supermarkets
106
-
107
- ## Usage
108
-
109
- To use compare_supermarkets call $ 'compare_supermarkets'
110
- and follow the prompts. The more specific you are the faster the search results appear
111
- and there will be less items to compare.
112
-
113
-
114
- ## Contributing
115
-
116
- Bug reports and pull requests are welcome on GitHub at https://github.com/happymelonbox/compare_supermarkets
117
-
118
- ## License
119
-
120
- The gem is available as open source under the terms of the [MIT License](https://opensource.org
121
- /licenses/MIT).
83
+ - !ruby/object:Gem::Dependency
84
+ name: watir
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 6.19.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 6.19.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: selenium-webdriver
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 3.142.7
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 3.142.7
111
+ description: Will search Woolworths and Coles online stores for prices based on an
112
+ input search parameter **Google Chrome Required**
122
113
  email:
123
- - howes.j.j@gmail.com
114
+ - happymelonbox@gmail.com
124
115
  executables:
125
116
  - compare_supermarkets
126
117
  extensions: []
@@ -134,6 +125,7 @@ files:
134
125
  - lib/compare_supermarkets/cli.rb
135
126
  - lib/compare_supermarkets/product.rb
136
127
  - lib/compare_supermarkets/scraper.rb
128
+ - lib/compare_supermarkets/supermarket.rb
137
129
  - lib/compare_supermarkets/version.rb
138
130
  homepage: http://rubygems.org/gems/compare_supermarkets
139
131
  licenses: