cb_nitride 0.0.7 → 0.0.8

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: 8e65cd07a27ad73f35e02965cba6a37ca8905da1
4
- data.tar.gz: d1493641becc9c16afac1cd1fadbc1a48802bcc6
3
+ metadata.gz: 5e1a3ea7c1e6df70c161f8b71a2b6f3a8723631c
4
+ data.tar.gz: e612a52d76006ab7d06499b2e09b55217bcda7f4
5
5
  SHA512:
6
- metadata.gz: 5552b6e951a91866a0597e77789ab300d148113fff6a7e306eea35e5e0ca54d62c2b683cfc9357556da87271a601597e17629a8d1342a3ad502b20a17235bbe8
7
- data.tar.gz: 45c288aece4982dbd1f51516c8dd1d22d06f46e69c19a5a294100493b1cef86e127e4fc8c59ba2f281ad9d7df4cc6609caffbf878cdd4852e3340e744f3610f4
6
+ metadata.gz: 63af916a67f363d21a7c777a5e72af35b1d989454b4b41f4838c8bd1446a6283d533a961994fa8bedfbc3131db3fcf97dbbd978ea85853df9121d271ec3b8aeb
7
+ data.tar.gz: 00e010e4c8ebd8a77cf447c2e8ed3bc76a2742738e8e3017fb6844bc394d786bdffd83d70ebf5bf942fced99d5f38401250115cc64deb3d32bd0c2c430681329
@@ -1,52 +1,85 @@
1
1
  module CbNitride
2
2
  class DiamondNumberGenerator
3
3
 
4
+ #TODO: Refactor into DiamondNumberSet with sorting capabilities instead of array of array of array.
5
+
6
+ NEW_RELEASES_URL = "http://www.previewsworld.com/Home/1/1/71/952"
7
+ UPCOMING_RELEASES_URL = "http://www.previewsworld.com/Home/1/1/71/954"
8
+
4
9
  attr_reader :month, :year
5
- attr_accessor :count
6
10
 
7
11
  MONTH_CODES = ['JAN', 'FEB', 'MAR', 'APR', 'JUN', 'MAY', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC']
8
12
  YEAR_CODES = ['06','07','08','09','10','11','12','13']
9
13
 
10
- def self.generate
11
- new.formatted_numbers
14
+ def self.generate_all!
15
+ new.brute_force_formatted_numbers
12
16
  end
13
17
 
14
- def initialize(year = nil, options = {})
15
- @target_month = month
16
- @target_year = year
18
+ def self.generate_imminent!
19
+ new.imminent_releases
17
20
  end
18
21
 
19
- def formatted_numbers
20
- YEAR_CODES.map do |year|
21
- MONTH_CODES.map do |month|
22
- generate_numbers(year, month)
22
+ def initialize(year_range = nil, month_range = nil, options = {})
23
+ @year_range = year_range || YEAR_CODES
24
+ @month_range = month_range || MONTH_CODES
25
+ end
26
+
27
+ def imminent_releases
28
+ [new_releases_page, upcoming_releases_page].map do |page|
29
+ extract_diamond_numbers(page)
30
+ end.flatten
31
+ end
32
+
33
+ def brute_force_formatted_numbers
34
+ year_codes.map do |year|
35
+ month_codes.map do |month|
36
+ generate_numbers(year, month)
23
37
  end
24
38
  end
25
39
  end
26
40
 
27
41
  def all_for_year
28
- MONTH_CODES.map do |month|
42
+ month_codes.map do |month|
29
43
  generate_numbers(year, month)
30
44
  end.flatten
31
45
  end
46
+
32
47
  private
33
48
 
34
49
  def generate_numbers(year, month)
35
50
  (1...3000).map do |num|
36
- format_single_number(year, month, num)
51
+ format_number(year, month, num)
37
52
  end.flatten.compact
38
53
  end
39
54
 
40
- def format_single_number(year, month, num)
41
- month + year + calculate_zeroes(num)
42
- end
43
-
44
- def formatted_number(num)
55
+ def format_number(year, month, num)
45
56
  month + year + calculate_zeroes(num)
46
57
  end
47
58
 
48
59
  def calculate_zeroes(num)
49
60
  ("0" * (4 - num.to_s.size)) + num.to_s
50
61
  end
62
+
63
+ def item_page(url)
64
+ Nokogiri::HTML(Mechanize.new.get(url).content)
65
+ end
66
+
67
+ def extract_diamond_numbers(page)
68
+ page.css('a').map do |link|
69
+ if link.attributes["href"].value.include? "stockItemID"
70
+ link.children.text
71
+ else
72
+ nil
73
+ end
74
+ end.compact
75
+ end
76
+
77
+ def new_releases_page
78
+ @_new_releases_page ||= item_page(NEW_RELEASES_URL)
79
+ end
80
+
81
+ def upcoming_releases_page
82
+ @_upcoming_releases_page ||= item_page(UPCOMING_RELEASES_URL)
83
+ end
51
84
  end
52
85
  end
@@ -1,6 +1,12 @@
1
1
  module CbNitride
2
2
  module HasherMethods
3
3
 
4
+ attr_accessor :error_array
5
+
6
+ def error_array
7
+ @error_array ||= []
8
+ end
9
+
4
10
  def find_text_with(code)
5
11
  item_page.css(code).text.strip
6
12
  end
@@ -14,7 +20,11 @@ module CbNitride
14
20
  end
15
21
 
16
22
  def clean_date_string(date)
17
- Date.strptime(date.match(/\d+[\/]\d+[\/]\d+/).to_s, "%m/%d/%Y")
23
+ if date == ""
24
+ error_array << "No Release Date"
25
+ else
26
+ Date.strptime(date.match(/\d+[\/]\d+[\/]\d+/).to_s, "%m/%d/%Y")
27
+ end
18
28
  end
19
29
  end
20
30
  end
@@ -61,7 +61,8 @@ module CbNitride
61
61
  release_date: clean_date_string(native_hash["Est Ship Date"]),
62
62
  price: clean_price_float(native_hash["Price Before Discount"]),
63
63
  category_code: native_hash["Category Code"],
64
- state: :private
64
+ state: :private,
65
+ errors: error_array
65
66
  }
66
67
  end
67
68
 
@@ -53,7 +53,7 @@ module CbNitride
53
53
  end
54
54
 
55
55
  def uncategorized_hash
56
- @_uncategorized_hash ||= {
56
+ @_uncategorized_hash ||= {
57
57
  title: find_text_with(TITLE_CLASS),
58
58
  diamond_number: diamond_number,
59
59
  stock_number: get_stock_number,
@@ -63,7 +63,8 @@ module CbNitride
63
63
  description: find_text_with(DESCRIPTION_CLASS),
64
64
  release_date: clean_date_string(find_text_with(RELEASE_CLASS)),
65
65
  price: clean_price_float(find_text_with(PRICE_CLASS)),
66
- state: :public
66
+ state: :public,
67
+ errors: error_array
67
68
  }
68
69
  end
69
70
 
@@ -74,8 +75,6 @@ module CbNitride
74
75
  )
75
76
  end
76
77
 
77
-
78
-
79
78
  def item_page
80
79
  @item_page ||= Nokogiri::HTML(agent.get(SEARCH_URL + diamond_number).content)
81
80
  end
@@ -1,3 +1,3 @@
1
1
  module CbNitride
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
data/lib/cb_nitride.rb CHANGED
@@ -12,7 +12,7 @@ require "cb_nitride/diamond_item"
12
12
  require "cb_nitride/diamond_number_generator"
13
13
 
14
14
  module CbNitride
15
- def self.item(diamond_number, qualified = false)
15
+ def self.item(diamond_number)
16
16
  unless qualified?
17
17
  PublicHasher.item(diamond_number)
18
18
  else
@@ -21,7 +21,19 @@ module CbNitride
21
21
  end
22
22
 
23
23
  def self.generate_diamond_numbers
24
- @_generate_diamond_numbers ||= DiamondNumberGenerator.generate
24
+ @_generate_diamond_numbers ||= DiamondNumberGenerator.generate_all!
25
+ end
26
+
27
+ def self.scrape_imminent!
28
+ DiamondNumberGenerator.generate_imminent!.map do |diamond_number|
29
+ diamond_item = item(diamond_number)
30
+ if diamond_item.nil?
31
+ binding.pry
32
+ else
33
+ puts "Recorded #{diamond_item.title} (#{diamond_number})"
34
+ diamond_item
35
+ end
36
+ end
25
37
  end
26
38
 
27
39
  def self.scrape_all!
@@ -32,8 +44,8 @@ module CbNitride
32
44
  if diamond_item.nil?
33
45
  binding.pry
34
46
  else
47
+ puts "Recorded #{diamond_item.title} (#{diamond_number})"
35
48
  diamond_item
36
- puts "Recorded #{diamond_item.title}"
37
49
  end
38
50
  end
39
51
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cb_nitride
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Jarvis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-27 00:00:00.000000000 Z
11
+ date: 2013-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler