tf2r 0.2.0 → 0.2.1

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: 4c5bd71115ed3cebd26737dc98ab7dcc23355253
4
- data.tar.gz: 1eef157620f392d7f5247cc262eef47a02451fcd
3
+ metadata.gz: d3eea3425354043f9ded54a379f71f341cf8010e
4
+ data.tar.gz: d0104958be84f7c9ddada47b9149c60a5fcdb565
5
5
  SHA512:
6
- metadata.gz: dab7f6734488422f90ca4defcd8af4f071eb6778a36f90551721b5a778bee9bb9e96f3b41d03f7126b42574b09274251efbcc3a7510277ceed2f95c339282d7b
7
- data.tar.gz: e3755809104357d54bdfec5bc792565914d1e9c6ab230d0f349dcfb3cb54f51da60e4101b6c0820ad8abbebeeabe420bc6c5e2d68e2742660283046df7ad8c95
6
+ metadata.gz: 69b5e73e168c64ea21deae35c377854651add86269f3b371f1a453fc64e255b508e8affcd283f776ae10d444760ba821bb0f5eaa237f0b9b141e5efcfd97be23
7
+ data.tar.gz: 27e52dac9061e970a47073b5fffbdc47eb37e3f54d9bf569a1c1ad3a9eaa160d7ab7fde95a428883f231333fda3cae80ea8661cf4576935dca9d61e9e61338bf
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tf2r (0.2.0)
4
+ tf2r (0.2.1)
5
5
  mechanize (~> 2.7)
6
6
 
7
7
  GEM
@@ -11,7 +11,7 @@ GEM
11
11
  cane (2.6.2)
12
12
  parallel
13
13
  coderay (1.1.0)
14
- coveralls (0.7.0)
14
+ coveralls (0.7.1)
15
15
  multi_json (~> 1.3)
16
16
  rest-client
17
17
  simplecov (>= 0.7)
@@ -75,7 +75,7 @@ GEM
75
75
  term-ansicolor (1.3.0)
76
76
  tins (~> 1.0)
77
77
  thor (0.19.1)
78
- tins (1.3.0)
78
+ tins (1.3.1)
79
79
  unf (0.1.4)
80
80
  unf_ext
81
81
  unf_ext (0.0.6)
@@ -91,7 +91,7 @@ PLATFORMS
91
91
  DEPENDENCIES
92
92
  bundler (~> 1.3)
93
93
  cane (~> 2.6)
94
- coveralls (~> 0.7)
94
+ coveralls (~> 0.7.1)
95
95
  pry (~> 0.10)
96
96
  rake (~> 10.0)
97
97
  rspec (~> 3.0)
@@ -2,6 +2,7 @@ require 'mechanize'
2
2
  require 'pry'
3
3
 
4
4
  require 'tf2r/api'
5
+ require 'tf2r/text_helpers'
5
6
  require 'tf2r/raffle'
6
7
  require 'tf2r/scraper'
7
8
  require 'tf2r/version'
@@ -3,6 +3,8 @@ module TF2R
3
3
  # raffle from the Scraper and API.
4
4
  # TODO: make this an actuall wrapper instead of accepting pre-made info.
5
5
  class Raffle
6
+ include TF2R::TextHelpers
7
+
6
8
  attr_reader :link_snippet, :api_info, :scraper_info
7
9
 
8
10
  def initialize(link_snippet, api_info, scraper_info)
@@ -24,11 +26,21 @@ module TF2R
24
26
  end
25
27
 
26
28
  def participants
27
- @api_info['newentry']
29
+ @normalized_participants ||= normalize_entries(@api_info['newentry'])
28
30
  end
29
31
 
30
32
  private
31
33
 
34
+ def normalize_entries(entries)
35
+ entries.map do |entry|
36
+ entry[:steam_id] = extract_steam_id entry.delete('link')
37
+ entry[:username] = entry.delete('name')
38
+ entry[:colour] = entry.delete('color').downcase
39
+ entry[:avatar_link] = entry.delete('avatar')
40
+ end
41
+ entries
42
+ end
43
+
32
44
  def title
33
45
  @scraper_info[0][:title]
34
46
  end
@@ -1,6 +1,8 @@
1
1
  module TF2R
2
2
  # @author Justin Kim
3
3
  class Scraper
4
+ include TF2R::TextHelpers
5
+
4
6
  class InvalidUserPage < StandardError; end
5
7
  # Creates a Scraper. Pass values using the options hash.
6
8
  #
@@ -65,11 +67,9 @@ module TF2R
65
67
  # @return [Array]
66
68
  # * the raffle Hash from scrape_raffle_for_raffle
67
69
  # * the creator Hash from scrape_raffle_for_creator
68
- # * the participants Array from scrape_raffle_for_participants
69
70
  def scrape_raffle(page)
70
71
  [scrape_raffle_for_raffle(page),
71
- scrape_raffle_for_creator(page),
72
- scrape_raffle_for_participants(page)]
72
+ scrape_raffle_for_creator(page)]
73
73
  end
74
74
 
75
75
  # Scrapes a raffle page for information about the creator.
@@ -156,9 +156,10 @@ module TF2R
156
156
  start_time: start_time, end_time: end_time}
157
157
  end
158
158
 
159
- # Scrapes a raffle page for all the participants.
159
+ # @deprecated Please use {#TF2R::API} instead. The API provides a far more
160
+ # efficient and reliable method of retrieving the entry list.
160
161
  #
161
- # TODO: add an example
162
+ # Scrapes a raffle page for all the participants.
162
163
  #
163
164
  # @param page [Mechanize::Page] the raffle page.
164
165
  # @return [Array] contains Hashes representing each of the participants,
@@ -167,6 +168,8 @@ module TF2R
167
168
  # * :username (+String+) — the participant's username.
168
169
  # * :colour (+String+) — hex colour code of the participant's username.
169
170
  def scrape_raffle_for_participants(page)
171
+ warn '[DEPRECATION] `scrape_raffle_for_participants` is deprecated. '\
172
+ 'Please use `TF2R::API` instead.'
170
173
  participants = []
171
174
  participant_divs = page.parser.css('.pentry')
172
175
  participant_divs.each do |participant|
@@ -259,29 +262,6 @@ module TF2R
259
262
  {name: name, description: description, colour: colour}
260
263
  end
261
264
 
262
- # Extracts a SteamID64 from a TF2R user link.
263
- #
264
- # @example
265
- # extract_steam_id('http://tf2r.com/user/76561198061719848.html')
266
- # #=> 76561198061719848
267
- #
268
- # @param href [String] The full user profile link.
269
- # @return [Fixnum] The Steam ID.
270
- def extract_steam_id(href)
271
- /http:\/\/tf2r.com\/user\/(\d+)\.html/.match(href)[1].to_i
272
- end
273
-
274
- # Extracts a hex colour code.
275
- #
276
- # @example
277
- # extract_colour('color:#70B01B;') #=> '70b01b'
278
- #
279
- # @param href [String] Any string containing a hex colour code.
280
- # @return [String] The hex colour code, downcased.
281
- def extract_colour(str)
282
- /#(\w+)\s*;/.match(str)[1].downcase
283
- end
284
-
285
265
  # Extracts the Time from any String.
286
266
  #
287
267
  # @param [String] a String containing a unix timestamp value.
@@ -298,14 +278,6 @@ module TF2R
298
278
  extract_time(td.attribute('data-rsend-unix').to_s)
299
279
  end
300
280
 
301
- # Extract the link_snippet from a path or link.
302
- #
303
- # @param [String] any raffle link or path.
304
- # @return [String] the raffle's link snippet.
305
- def extract_link_snippet(text)
306
- /\/(k.+)\.html/.match(text)[1]
307
- end
308
-
309
281
  # Extract the title from a raffle title string.
310
282
  #
311
283
  # @param [String] the raffle title string.
@@ -0,0 +1,34 @@
1
+ module TF2R
2
+ module TextHelpers
3
+ # Extracts a hex colour code.
4
+ #
5
+ # @example
6
+ # extract_colour('color:#70B01B;') #=> '70b01b'
7
+ #
8
+ # @param href [String] Any string containing a hex colour code.
9
+ # @return [String] The hex colour code, downcased.
10
+ def extract_colour(str)
11
+ /#(\w+)\s*;/.match(str)[1].downcase
12
+ end
13
+
14
+ # Extract the link_snippet from a path or link.
15
+ #
16
+ # @param [String] any raffle link or path.
17
+ # @return [String] the raffle's link snippet.
18
+ def extract_link_snippet(text)
19
+ /\/(k.+)\.html/.match(text)[1]
20
+ end
21
+
22
+ # Extracts a SteamID64 from a TF2R user link.
23
+ #
24
+ # @example
25
+ # extract_steam_id('http://tf2r.com/user/76561198061719848.html')
26
+ # #=> 76561198061719848
27
+ #
28
+ # @param href [String] The full user profile link.
29
+ # @return [Fixnum] The Steam ID.
30
+ def extract_steam_id(href)
31
+ /http:\/\/tf2r.com\/user\/(\d+)\.html/.match(href)[1].to_i
32
+ end
33
+ end
34
+ end
@@ -1,3 +1,3 @@
1
1
  module TF2R
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
@@ -74,7 +74,6 @@ describe TF2R::Scraper do
74
74
  it 'returns the same as its child methods' do
75
75
  expect(result[0]).to eql(scraper.scrape_raffle_for_raffle(raffle_page))
76
76
  expect(result[1]).to eql(scraper.scrape_raffle_for_creator(raffle_page))
77
- expect(result[2]).to eql(scraper.scrape_raffle_for_participants(raffle_page))
78
77
  end
79
78
  end
80
79
 
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency 'rake', '~> 10.0'
25
25
 
26
26
  spec.add_development_dependency 'cane', '~> 2.6'
27
- spec.add_development_dependency 'coveralls', '~> 0.7'
27
+ spec.add_development_dependency 'coveralls', '~> 0.7.1'
28
28
  spec.add_development_dependency 'pry', '~> 0.10'
29
29
  spec.add_development_dependency 'rspec', '~> 3.0'
30
30
  spec.add_development_dependency 'vcr', '~> 2.9'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tf2r
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Kim
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-14 00:00:00.000000000 Z
11
+ date: 2014-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0.7'
61
+ version: 0.7.1
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0.7'
68
+ version: 0.7.1
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: pry
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -157,6 +157,7 @@ files:
157
157
  - lib/tf2r/api.rb
158
158
  - lib/tf2r/raffle.rb
159
159
  - lib/tf2r/scraper.rb
160
+ - lib/tf2r/text_helpers.rb
160
161
  - lib/tf2r/version.rb
161
162
  - spec/raffle_spec.rb
162
163
  - spec/raffles.html