cb_nitride 0.0.16 → 0.1.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: 12973fe1a33d9c54223ba2b7d87cd35603d9f4b2
4
- data.tar.gz: 215c085a8fbc26a068e0ca59f3068b5b7a3edd19
3
+ metadata.gz: 927f221545d3f6f7b9672f6df48e4a72b0eace45
4
+ data.tar.gz: 51223a4207e9f7ca245aea639deba2da030c2cce
5
5
  SHA512:
6
- metadata.gz: 19688eb3a9fa80ff2214ab3225264b0411ecb9722aa8103d4c624d40058cc8dd1e1c50f9919667e85740c404851d1c3e27d19d7272a62ecb4f0861ebd37b0482
7
- data.tar.gz: 4ff6384a19643717c5cec0f75ed3cb5f4d8de796962e8fd1433713d5fe29f517168b5bc3553f2fa753b25e6d473c8dc87dd480980bb918adf7e6d59e4128dea8
6
+ metadata.gz: 8adb9951857add021386eeb4b67e5cf0600897f9812fd9affb9bb7db1f0a5da633876df7b4543609fb5bfe3890c93446d403a7d6603a6bdf6f6e1ad7d82b3e54
7
+ data.tar.gz: 4b40e1825f723443ec74c85440d28e6a8a2808c11f5cbea9b102cde2e9f43a992137c5ee8028d978d918f6387918b675b0ebeb6d8f3554b6180b18a8e7435b2a
@@ -0,0 +1,25 @@
1
+ module CbNitride
2
+ class DiamondNumberFormatter
3
+ attr_reader :month, :year, :num
4
+
5
+ def self.format(year: year, month: month, num: num)
6
+ new(year: year, month: month, num: num).format
7
+ end
8
+
9
+ def initialize(year: year, month: month, num: num)
10
+ @year = year
11
+ @month = month
12
+ @num = num
13
+ end
14
+
15
+ def format
16
+ month + year + calculate_zeroes
17
+ end
18
+
19
+ private
20
+
21
+ def calculate_zeroes
22
+ ("0" * (4 - num.to_s.size)) + num.to_s
23
+ end
24
+ end
25
+ end
@@ -1,36 +1,30 @@
1
1
  module CbNitride
2
- class DiamondNumberGenerator
3
-
4
- #TODO: Refactor into DiamondNumberSet with sorting capabilities instead of array of array of array.
5
-
2
+ class DiamondNumberSet
6
3
  NEW_RELEASES_URL = "http://www.previewsworld.com/Home/1/1/71/952"
7
4
  UPCOMING_RELEASES_URL = "http://www.previewsworld.com/Home/1/1/71/954"
8
-
9
- attr_reader :month, :year
10
-
11
5
  MONTH_CODES = ['JAN', 'FEB', 'MAR', 'APR', 'JUN', 'MAY', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC']
12
- YEAR_CODES = ['06','07','08','09','10','11','12','13']
6
+ YEAR_CODES = ['96', '97', '98', '99', '00', '01', '02', '03', '04', '05' '06','07','08','09','10','11','12','13']
7
+ POSSIBLE_DIAMOND_NUMBERS = (1...9999)
13
8
 
14
- def self.generate_all!
15
- new.brute_force_formatted_numbers
9
+ def self.generate_imminent_diamond_numbers
10
+ new.imminent_numbers
16
11
  end
17
12
 
18
- def self.generate_imminent!
19
- new.imminent_releases
13
+ def self.generate_all_diamond_numbers
14
+ new.brute_force_formatted_numbers
20
15
  end
21
16
 
22
- def initialize(year_range = nil, month_range = nil, options = {})
23
- @year_range = year_range || YEAR_CODES
24
- @month_range = month_range || MONTH_CODES
17
+ def self.generate_for(years: years, months: months)
18
+ new.brute_force_formatted_numbers(year_range: years, month_range: months)
25
19
  end
26
20
 
27
- def imminent_releases
21
+ def imminent_numbers
28
22
  [new_releases_page, upcoming_releases_page].map do |page|
29
23
  extract_diamond_numbers(page)
30
24
  end.flatten
31
25
  end
32
26
 
33
- def brute_force_formatted_numbers
27
+ def brute_force_formatted_numbers(year_range: year_range || YEAR_CODES, month_range: month_range || MONTH_CODES)
34
28
  year_range.map do |year|
35
29
  month_range.map do |month|
36
30
  generate_numbers(year, month)
@@ -38,30 +32,30 @@ module CbNitride
38
32
  end
39
33
  end
40
34
 
35
+ private
36
+
41
37
  def all_for_year
42
- month_codes.map do |month|
38
+ MONTH_CODES.map do |month|
43
39
  generate_numbers(year, month)
44
40
  end.flatten
45
41
  end
46
42
 
47
- private
48
-
49
43
  def generate_numbers(year, month)
50
- (1...3000).map do |num|
51
- format_number(year, month, num)
44
+ POSSIBLE_DIAMOND_NUMBERS.map do |num|
45
+ DiamondNumberFormatter.format(year: year, month: month, num: num)
52
46
  end.flatten.compact
53
47
  end
54
48
 
55
- def format_number(year, month, num)
56
- month + year + calculate_zeroes(num)
49
+ def item_page(url)
50
+ Nokogiri::HTML(Mechanize.new.get(url).content)
57
51
  end
58
52
 
59
- def calculate_zeroes(num)
60
- ("0" * (4 - num.to_s.size)) + num.to_s
53
+ def new_releases_page
54
+ @_new_releases_page ||= item_page(NEW_RELEASES_URL)
61
55
  end
62
56
 
63
- def item_page(url)
64
- Nokogiri::HTML(Mechanize.new.get(url).content)
57
+ def upcoming_releases_page
58
+ @_upcoming_releases_page ||= item_page(UPCOMING_RELEASES_URL)
65
59
  end
66
60
 
67
61
  def extract_diamond_numbers(page)
@@ -73,13 +67,5 @@ module CbNitride
73
67
  end
74
68
  end.compact
75
69
  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
84
70
  end
85
71
  end
@@ -10,6 +10,7 @@ module CbNitride
10
10
  end
11
11
 
12
12
  OF_PATTERN = /[(].*[Oo][fF].*\d+.*[)]/
13
+
13
14
  def series_title
14
15
  @_series_title ||=
15
16
  if clean_title.include? "#"
@@ -1,3 +1,3 @@
1
1
  module CbNitride
2
- VERSION = "0.0.16"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/cb_nitride.rb CHANGED
@@ -8,7 +8,8 @@ require "cb_nitride/public_hasher"
8
8
  require "cb_nitride/private_hasher"
9
9
  require "cb_nitride/category_sorter"
10
10
  require "cb_nitride/diamond_item"
11
- require "cb_nitride/diamond_number_generator"
11
+ require "cb_nitride/diamond_number_set"
12
+ require "cb_nitride/diamond_number_formatter"
12
13
  require "cb_nitride/title_formatter"
13
14
 
14
15
  module CbNitride
@@ -19,41 +20,4 @@ module CbNitride
19
20
  PublicHasher.item(diamond_number)
20
21
  end
21
22
  end
22
-
23
- def self.generate_diamond_numbers
24
- @_generate_diamond_numbers ||= DiamondNumberGenerator.generate_all!
25
- end
26
-
27
- def self.scrape_imminent!
28
- agent = DiamondLogin.agent if qualified?
29
- DiamondNumberGenerator.generate_imminent!.map do |diamond_number|
30
- puts "Looking for #{diamond_number}"
31
- if qualified?
32
- diamond_item = item(diamond_number, agent: agent)
33
- else
34
- diamond_item = item (diamond_number)
35
- end
36
- if diamond_item.nil?
37
- puts 'Invalid diamond item'
38
- next
39
- else
40
- puts "Recorded #{diamond_item.title} (#{diamond_number})"
41
- diamond_item
42
- end
43
- end
44
- end
45
-
46
- def self.scrape_all!
47
- generate_diamond_numbers.flatten.map do |diamond_number|
48
- diamond_item = item(diamond_number)
49
- if diamond_item.nil?
50
- puts "invalid diamond Item"
51
- next
52
- else
53
- puts "Recorded #{diamond_item.title} (#{diamond_number})"
54
- diamond_item
55
- end
56
- end.flatten
57
- end
58
-
59
23
  end
@@ -0,0 +1,9 @@
1
+ require_relative '../test_helper'
2
+
3
+ class DiamondNumberFormatterTest < MiniTest::Unit::TestCase
4
+ def test_that_it_produces_the_right_string
5
+ number = CbNitride::DiamondNumberFormatter.format(month: "AUG", num:'0831', year: '88')
6
+
7
+ assert_equal "AUG880831", number
8
+ end
9
+ 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.16
4
+ version: 0.1.0
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-29 00:00:00.000000000 Z
11
+ date: 2013-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -84,7 +84,8 @@ files:
84
84
  - lib/cb_nitride/configuration.rb
85
85
  - lib/cb_nitride/diamond_item.rb
86
86
  - lib/cb_nitride/diamond_login.rb
87
- - lib/cb_nitride/diamond_number_generator.rb
87
+ - lib/cb_nitride/diamond_number_formatter.rb
88
+ - lib/cb_nitride/diamond_number_set.rb
88
89
  - lib/cb_nitride/exceptions.rb
89
90
  - lib/cb_nitride/hasher_methods.rb
90
91
  - lib/cb_nitride/module_methods.rb
@@ -115,6 +116,7 @@ files:
115
116
  - test/unit/configuration_test.rb
116
117
  - test/unit/diamond_item_test.rb
117
118
  - test/unit/diamond_login_test.rb
119
+ - test/unit/diamond_number_formatter_test.rb
118
120
  - test/unit/private_hasher_test.rb
119
121
  - test/unit/public_hasher_test.rb
120
122
  - test/unit/pull_test.rb
@@ -167,6 +169,7 @@ test_files:
167
169
  - test/unit/configuration_test.rb
168
170
  - test/unit/diamond_item_test.rb
169
171
  - test/unit/diamond_login_test.rb
172
+ - test/unit/diamond_number_formatter_test.rb
170
173
  - test/unit/private_hasher_test.rb
171
174
  - test/unit/public_hasher_test.rb
172
175
  - test/unit/pull_test.rb