Class: Gatherer::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/gatherer/client.rb

Instance Method Summary collapse

Instance Method Details

#card_from(scraper) ⇒ Object



19
20
21
22
# File 'lib/gatherer/client.rb', line 19

def card_from(scraper)
  parser = Gatherer::CardParser.new(page_from(scraper))
  Card.new_from_parser(parser)
end

#expansion_abbreviation_for(title, file = nil) ⇒ Object



42
43
44
45
46
47
# File 'lib/gatherer/client.rb', line 42

def expansion_abbreviation_for(title, file = nil)
  file ||= open(Scraper.new(expansion: title).url)
  doc = Nokogiri::HTML(file)
  set_images = doc.css('div#ctl00_ctl00_ctl00_MainContent_SubContent_SubContent_ctl00_listRepeater_ctl00_cardSetCurrent img')
  abbreviation = set_images.first['src'].match(/&set=(.[^&]*)/)[1] unless set_images.empty?
end

#expansion_titles(file = nil) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/gatherer/client.rb', line 33

def expansion_titles(file = nil)
  file ||= open('http://gatherer.wizards.com')
  doc = Nokogiri::HTML(file)
  expansion_titles = doc.css('select#ctl00_ctl00_MainContent_Content_SearchControls_setAddText')
    .css('option')
    .map {|option| option['value'] }
    .select {|expansion| !expansion.empty?}
end

#expansions(homepage_file = nil, expansion_file = nil) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/gatherer/client.rb', line 24

def expansions(homepage_file = nil, expansion_file = nil)
  expansion_titles(homepage_file).map do |title|
    Gatherer::Expansion.new(
      title: title,
      abbreviation: expansion_abbreviation_for(title, expansion_file)
    )
  end
end

#fetch_by_multiverse_id(id) ⇒ Object



7
8
9
# File 'lib/gatherer/client.rb', line 7

def fetch_by_multiverse_id(id)
  card_from(multiverse_scraper(id))
end

#multiverse_scraper(id) ⇒ Object



11
12
13
# File 'lib/gatherer/client.rb', line 11

def multiverse_scraper(id)
  Gatherer::Scraper.new(multiverse_id: id)
end

#page_from(scraper) ⇒ Object



15
16
17
# File 'lib/gatherer/client.rb', line 15

def page_from(scraper)
  open(scraper.url)
end