gatherer 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -21,13 +21,26 @@ module Gatherer
21
21
  Card.new_from_parser(parser)
22
22
  end
23
23
 
24
- def expansions(file = nil)
25
- file ||= open('http://gatherer.wizards.com')
26
- doc = Nokogiri::HTML(file)
27
- expansions = doc.css('select#ctl00_ctl00_MainContent_Content_SearchControls_setAddText')
24
+ def expansions(homepage_file = nil, expansion_file = nil)
25
+ homepage_file ||= open('http://gatherer.wizards.com')
26
+ doc = Nokogiri::HTML(homepage_file)
27
+ expansion_titles = doc.css('select#ctl00_ctl00_MainContent_Content_SearchControls_setAddText')
28
28
  .css('option')
29
29
  .map {|option| option['value'] }
30
30
  .select {|expansion| !expansion.empty?}
31
+ expansion_titles.map do |title|
32
+ Gatherer::Expansion.new(
33
+ title: title,
34
+ abbreviation: expansion_abbreviation_for(title, expansion_file)
35
+ )
36
+ end
37
+ end
38
+
39
+ def expansion_abbreviation_for(title, file = nil)
40
+ file ||= open(Scraper.new(expansion: title).url)
41
+ doc = Nokogiri::HTML(file)
42
+ set_images = doc.css('div#ctl00_ctl00_ctl00_MainContent_SubContent_SubContent_ctl00_listRepeater_ctl00_cardSetCurrent img')
43
+ abbreviation = set_images.first['src'].match(/&set=(.[^&]*)/)[1] unless set_images.empty?
31
44
  end
32
45
  end
33
46
  end
@@ -19,8 +19,9 @@ module Gatherer
19
19
  BASE_PATH + @subpath + (@query.empty? ? '' : '?' + @query)
20
20
  end
21
21
 
22
- def set(name)
23
- "set=[#{name}]"
22
+ def expansion(name)
23
+ @subpath = "/Pages/Search/Default.aspx"
24
+ "set=[\"#{name}\"]"
24
25
  end
25
26
 
26
27
  def page(number)
@@ -1,3 +1,3 @@
1
1
  module Gatherer
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gatherer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-11 00:00:00.000000000 Z
12
+ date: 2013-01-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty