Class: Gatherer::Scraper

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

Constant Summary collapse

BASE_PATH =
"http://gatherer.wizards.com"

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Scraper

Returns a new instance of Scraper.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/gatherer/scraper.rb', line 5

def initialize(params = {})
  @query = ''
  @subpath = ''

  options = params.map do |k,v|
    send(k, v)
  end

  if options
    @query = URI.encode(options.join('&'))
  end
end

Instance Method Details

#expansion(name) ⇒ Object



22
23
24
25
# File 'lib/gatherer/scraper.rb', line 22

def expansion(name)
  @subpath = "/Pages/Search/Default.aspx"
  "set=[\"#{name}\"]"
end

#multiverse_id(id) ⇒ Object



31
32
33
34
# File 'lib/gatherer/scraper.rb', line 31

def multiverse_id(id)
  @subpath = "/Pages/Card/Details.aspx"
  "multiverseid=#{id}"
end

#page(number) ⇒ Object



27
28
29
# File 'lib/gatherer/scraper.rb', line 27

def page(number)
  "page=#{number}"
end

#urlObject



18
19
20
# File 'lib/gatherer/scraper.rb', line 18

def url
  BASE_PATH + @subpath + (@query.empty? ? '' : '?' + @query)
end