class Tamiyo::GathererScrape

Public Class Methods

new(set_name) click to toggle source
# File lib/tamiyo/gatherer_scrape.rb, line 6
def initialize(set_name)
  @set_name = set_name
  @client = HTTPClient.new
end

Public Instance Methods

xml_card_name_details(card_id) click to toggle source
# File lib/tamiyo/gatherer_scrape.rb, line 20
def xml_card_name_details(card_id)
  path = 'Pages/Card/Details.aspx'
  query = '?multiverseid=%s' % card_id
  url = URI.escape "#{host}#{path}#{query}"
  response = @client.get url
  html = Nokogiri::HTML ampersand_fixed(response.body)
  # must apply these selectors separately for some reason
  html.css('.cardComponentContainer').css('[id$="nameRow"]')
end
xml_spoiler_rows() click to toggle source
# File lib/tamiyo/gatherer_scrape.rb, line 11
def xml_spoiler_rows
  path = 'Pages/Search/Default.aspx'
  query = '?output=spoiler&method=text&action=advanced&set=["%s"]&special=true' % @set_name.tr(' ', '+')
  url = URI.escape "#{host}#{path}#{query}"
  response = @client.get url
  html = Nokogiri::HTML ampersand_fixed(response.body)
  html.css 'div.textspoiler tr'
end

Private Instance Methods

ampersand_fixed(text) click to toggle source
# File lib/tamiyo/gatherer_scrape.rb, line 36
def ampersand_fixed(text)
  text.gsub /&(?![^;]{,4};)/, '&'
end
host() click to toggle source
# File lib/tamiyo/gatherer_scrape.rb, line 32
def host
  'http://gatherer.wizards.com/'
end