queenshop 0.0.5 → 0.0.6
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/lib/queenshop/config.rb +6 -9
- data/lib/queenshop/scraper.rb +6 -4
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51ff3a99efef2152c5528fc1377981e2802e74b0
|
4
|
+
data.tar.gz: c2e00a3763b9c6cf99f135424a66c2bb2f260400
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a78c3d74d6e22f3faf2944782d7526a58a1626579ca024c4366f0dc337745245c0aba6c26ff838ba6a39eca72ddac98a70a9b8696058342eff3b5414def917f
|
7
|
+
data.tar.gz: a827145c98212153608e90da678f7755815158621c47cfcacfdcb92dfd142833f29b47b88d77f8495341017fa0d4af66de5bb9176ea13cc237aa78662354e7d2
|
data/lib/queenshop/config.rb
CHANGED
@@ -9,8 +9,7 @@ module Validate
|
|
9
9
|
VALID_ARGS = [:item, :price, :pages]
|
10
10
|
|
11
11
|
def validate_args(args)
|
12
|
-
@parameters = {
|
13
|
-
|
12
|
+
@parameters = {item: '', price: '', pages: '1..7'}
|
14
13
|
args.each do |arg|
|
15
14
|
begin
|
16
15
|
match = /(?<key>.*?)=(?<value>.*)/.match(arg)
|
@@ -18,20 +17,19 @@ module Validate
|
|
18
17
|
value = check(match)
|
19
18
|
@parameters[match[:key].to_sym] = value
|
20
19
|
rescue StandardError
|
21
|
-
abort
|
20
|
+
abort "invalid usage...\n" << usage << "\n\n"
|
22
21
|
end
|
23
22
|
end
|
24
23
|
end # end validate_args
|
25
24
|
|
26
25
|
def check(match)
|
27
26
|
value = match[:value]
|
28
|
-
fail unless
|
29
|
-
value =~ /^(>|<|>=|<=|==)\d*.\d*?$/ if match[:key].to_sym.eql?(:price)
|
27
|
+
fail unless value =~ /^(>|<|>=|<=|==)\d*.\d*?$/ if match[:key].to_sym.eql?(:price)
|
30
28
|
# Float(value) if match[:key].to_sym.eql?(:price)
|
31
29
|
fail unless value =~ /^\d*([.]{2}\d*)?$/ if match[:key].to_sym.eql?(:pages)
|
32
30
|
value
|
33
31
|
rescue StandardError
|
34
|
-
abort
|
32
|
+
abort "invalid parameters"
|
35
33
|
end
|
36
34
|
|
37
35
|
def pages
|
@@ -51,11 +49,10 @@ module Validate
|
|
51
49
|
end
|
52
50
|
end
|
53
51
|
|
54
|
-
# basic config name conflic if called Config
|
55
52
|
class QConfig
|
56
53
|
include Validate
|
57
|
-
def initialize(args)
|
58
|
-
validate_args(args)
|
54
|
+
def initialize (args)
|
55
|
+
validate_args (args)
|
59
56
|
pages
|
60
57
|
end
|
61
58
|
end
|
data/lib/queenshop/scraper.rb
CHANGED
@@ -35,9 +35,9 @@ module QueenShopScraper
|
|
35
35
|
items = document.xpath(@item_selector)
|
36
36
|
# loop through the items and get the title and price
|
37
37
|
items.map do |item|
|
38
|
-
title = item.xpath(@title_selector).text
|
38
|
+
title = item.xpath(@title_selector).text()
|
39
39
|
price = item.xpath(@price_selector).text
|
40
|
-
strip_filter(title, price)
|
40
|
+
strip_filter(title, price) unless title.chomp().empty?
|
41
41
|
end
|
42
42
|
@result
|
43
43
|
end
|
@@ -67,12 +67,14 @@ module QueenShopScraper
|
|
67
67
|
end
|
68
68
|
|
69
69
|
def scrape (params=[])
|
70
|
+
params = ARGV.empty? ? params : ARGV
|
70
71
|
conf = QConfig.new(params)
|
71
72
|
@price_filter = conf.parameters[:price]
|
72
|
-
|
73
|
+
@title_selector << "/text()[contains(.,'#{conf.parameters[:item]}')]"
|
74
|
+
|
73
75
|
conf.pages.map do |page|
|
74
76
|
paginated_uri = "&page=#{page}"
|
75
|
-
fetch_result
|
77
|
+
fetch_result(paginated_uri)
|
76
78
|
end
|
77
79
|
@result
|
78
80
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: queenshop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Even Chang
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2015-
|
14
|
+
date: 2015-11-22 00:00:00.000000000 Z
|
15
15
|
dependencies: []
|
16
16
|
description: This is a gem scraping queenshop's website and returns the items with
|
17
17
|
corresponding prices
|
@@ -29,7 +29,7 @@ files:
|
|
29
29
|
- lib/queenshop.rb
|
30
30
|
- lib/queenshop/config.rb
|
31
31
|
- lib/queenshop/scraper.rb
|
32
|
-
homepage: http://rubygems.org/gems/
|
32
|
+
homepage: http://rubygems.org/gems/queenshop
|
33
33
|
licenses:
|
34
34
|
- MIT
|
35
35
|
metadata: {}
|
@@ -49,7 +49,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
49
49
|
version: '0'
|
50
50
|
requirements: []
|
51
51
|
rubyforge_project:
|
52
|
-
rubygems_version: 2.
|
52
|
+
rubygems_version: 2.4.6
|
53
53
|
signing_key:
|
54
54
|
specification_version: 4
|
55
55
|
summary: Scraper for Queenshop
|