reckless 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
  SHA1:
3
- metadata.gz: 86f695a892834cf350aa6981ef710d7f9ad8cb14
4
- data.tar.gz: b82ca334df61c7de41cc3db026f460beabe1e853
3
+ metadata.gz: 53f4083126cfa94e5b83e224f8ee62c494305ba2
4
+ data.tar.gz: a63667f90f8a125c607bf200ef290c3cae1e4062
5
5
  SHA512:
6
- metadata.gz: 2ceeeb085d34c513e223aa5361eaea13809b113d97983ad7e6ea94737c876abe3e55c70deed8ca1b34c0c69541229d615feec0e874e5de3f3794601da0006c7c
7
- data.tar.gz: ebb4f7980ad86c54b00f3bad118a498a164eeb3f91ae23ece37356307af360d6b3e1cd798e36ad0278cc8d434445dbc1efc9087f912795a54c6e082d251a7315
6
+ metadata.gz: 4b16403a225edc7d0e44e6b8214335bdc91542d44078a60bb9503036b05c1738e71e3e71d4485b7618ab9ac0f31eb294de08e5c7fcc7ae1de5ad1a52f90fb910
7
+ data.tar.gz: 7e2ebf32e6030699eb1dea881f924ab4aaf77d2786f1f30d0613b81253bb993b657ec38ce65041d539f5c95efef9dd99d52097ac0a1c25a24bd06246820d8939
data/.gitignore CHANGED
@@ -11,6 +11,7 @@ spec/reports
11
11
  test/tmp
12
12
  test/version_tmp
13
13
  tmp
14
+ Gemfile.lock
14
15
 
15
16
  # YARD artifacts
16
17
  .yardoc
data/README.md CHANGED
@@ -45,15 +45,30 @@ Each search result is a simple hash:
45
45
  :price => 11.99,
46
46
  :type => "New LP",
47
47
  :condition => "Good Condition",
48
- :store => "Milwaukee Ave"
48
+ :location => "Milwaukee Ave"
49
49
  }
50
50
  ```
51
51
 
52
+ Or you can access it as an object:
53
+
54
+ ```ruby
55
+ item = Reckless.search("Nirvana").results.first
56
+
57
+ item.artist
58
+ item.title
59
+ item.label
60
+ item.price
61
+ item.type
62
+ item.condition
63
+ item.location
64
+ ```
65
+
52
66
  ### Search options
53
67
 
54
- - `page` - Specify a page to fetch. Defaults to `1`
55
- - `format` - Choose record format: `LP`, `CD`, `DVD`. Defaults to `LP`
56
- - `store` - Choose store: `Broadway`, `Milwaukee` or `Loop`. Does not have a default.
68
+ - `page` - Specify a page to fetch. Defaults to `1`
69
+ - `format` - Choose record format: `LP`, `CD`, `DVD`. Defaults to `LP`
70
+ - `location` - Choose location: `Broadway`, `Milwaukee` or `Loop`. Does not have a default.
71
+ - `condition` - Specify record condition: `U` - Used, `N` - New.
57
72
 
58
73
  ## Testing
59
74
 
data/lib/reckless.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "nokogiri"
2
2
  require "faraday"
3
+ require "hashr"
3
4
 
4
5
  require "reckless/client"
5
6
  require "reckless/search"
@@ -28,10 +28,10 @@ module Reckless
28
28
 
29
29
  def search_options(options)
30
30
  {
31
- page: options[:page] || 1,
32
- format: options[:format] || "LP",
33
- cond: options[:cond] || "",
34
- store: options[:store] || ""
31
+ page: options[:page] || 1,
32
+ format: options[:format] || "LP",
33
+ cond: options[:condition] || "",
34
+ store: options[:location] || ""
35
35
  }
36
36
  end
37
37
  end
@@ -7,17 +7,7 @@ module Reckless
7
7
  end
8
8
 
9
9
  def parse
10
- find_result_elements.map do |node|
11
- {
12
- artist: normalize_artist(fetch_text(node, "artist")),
13
- title: fetch_text(node, "title"),
14
- label: fetch_text(node, "label"),
15
- price: fetch_price(node.css("td").last),
16
- type: fetch_type(node),
17
- condition: fetch_condition(node),
18
- store: fetch_store(node)
19
- }
20
- end
10
+ find_result_elements.map { |node| Hashr.new(fetch_record(node)) }
21
11
  end
22
12
 
23
13
  private
@@ -26,6 +16,18 @@ module Reckless
26
16
  @document.css("table.item")
27
17
  end
28
18
 
19
+ def fetch_record(node)
20
+ {
21
+ artist: normalize_artist(fetch_text(node, "artist")),
22
+ title: fetch_text(node, "title"),
23
+ label: fetch_text(node, "label"),
24
+ price: fetch_price(node.css("td").last),
25
+ type: fetch_type(node),
26
+ condition: fetch_condition(node),
27
+ location: fetch_location_name(node)
28
+ }
29
+ end
30
+
29
31
  def fetch_price(node)
30
32
  node.to_s.scan(/\$([\d\.]+)/).flatten.first.to_f
31
33
  end
@@ -53,7 +55,7 @@ module Reckless
53
55
  end
54
56
  end
55
57
 
56
- def fetch_store(node)
58
+ def fetch_location_name(node)
57
59
  match = node.to_s.scan(/<span style="color:#a33; font-weight: bold;">([\w\s]+).<\/span>/)
58
60
  match.flatten.first
59
61
  end
@@ -1,3 +1,3 @@
1
1
  module Reckless
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/reckless.gemspec CHANGED
@@ -12,6 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.add_dependency "json", "~> 1.8"
13
13
  spec.add_dependency "faraday", "~> 0.7"
14
14
  spec.add_dependency "nokogiri", "~> 1.5"
15
+ spec.add_dependency "hashr", "~> 0"
15
16
 
16
17
  spec.add_development_dependency "rake"
17
18
  spec.add_development_dependency "rspec", "~> 2.13"
@@ -46,8 +46,16 @@ describe Reckless::ResultsParser do
46
46
  expect(record[:condition]).to eq "Very Good"
47
47
  end
48
48
 
49
- it "includes store name" do
50
- expect(record[:store]).to eq "Broadway and Milwaukee Ave"
49
+ it "includes location name" do
50
+ expect(record[:location]).to eq "Broadway and Milwaukee Ave"
51
+ end
52
+
53
+ it "behaves like an object" do
54
+ methods = %w(artist title label price type condition location).map(&:to_sym)
55
+
56
+ methods.each do |name|
57
+ expect(record.send(name)).to eq record[name]
58
+ end
51
59
  end
52
60
  end
53
61
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reckless
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
  - Dan Sosedoff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-28 00:00:00.000000000 Z
11
+ date: 2014-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: hashr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rake
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -104,7 +118,6 @@ files:
104
118
  - .gitignore
105
119
  - .rspec
106
120
  - Gemfile
107
- - Gemfile.lock
108
121
  - LICENSE
109
122
  - README.md
110
123
  - Rakefile
data/Gemfile.lock DELETED
@@ -1,44 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- reckless (0.1.0)
5
- faraday (~> 0.7)
6
- json (~> 1.8)
7
- nokogiri (~> 1.5)
8
-
9
- GEM
10
- remote: https://rubygems.org/
11
- specs:
12
- diff-lcs (1.2.5)
13
- docile (1.1.0)
14
- faraday (0.8.9)
15
- multipart-post (~> 1.2.0)
16
- json (1.8.1)
17
- mini_portile (0.5.1)
18
- multi_json (1.8.2)
19
- multipart-post (1.2.0)
20
- nokogiri (1.6.0)
21
- mini_portile (~> 0.5.0)
22
- rake (10.1.1)
23
- rspec (2.14.1)
24
- rspec-core (~> 2.14.0)
25
- rspec-expectations (~> 2.14.0)
26
- rspec-mocks (~> 2.14.0)
27
- rspec-core (2.14.7)
28
- rspec-expectations (2.14.4)
29
- diff-lcs (>= 1.1.3, < 2.0)
30
- rspec-mocks (2.14.4)
31
- simplecov (0.8.2)
32
- docile (~> 1.1.0)
33
- multi_json
34
- simplecov-html (~> 0.8.0)
35
- simplecov-html (0.8.0)
36
-
37
- PLATFORMS
38
- ruby
39
-
40
- DEPENDENCIES
41
- rake
42
- reckless!
43
- rspec (~> 2.13)
44
- simplecov (~> 0.7)