Class: Scrapers::Imgur

Inherits:
Object
  • Object
show all
Defined in:
lib/scrapers/imgur.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeImgur

Returns a new instance of Imgur.



20
21
22
23
24
# File 'lib/scrapers/imgur.rb', line 20

def initialize
  @agent = Mechanize.new
  @url = URI.parse(IMGUR_TEMPLATE)
  @download = URI.parse(IMGUR_TEMPLATE)
end

Instance Attribute Details

#agentObject

Returns the value of attribute agent.



18
19
20
# File 'lib/scrapers/imgur.rb', line 18

def agent
  @agent
end

#downloadObject

Returns the value of attribute download.



18
19
20
# File 'lib/scrapers/imgur.rb', line 18

def download
  @download
end

#pageObject

Returns the value of attribute page.



18
19
20
# File 'lib/scrapers/imgur.rb', line 18

def page
  @page
end

#urlObject

Returns the value of attribute url.



18
19
20
# File 'lib/scrapers/imgur.rb', line 18

def url
  @url
end

Instance Method Details



26
27
28
29
30
31
# File 'lib/scrapers/imgur.rb', line 26

def download_link(code)
  make_url(code)
  retrieve_page()
  find_download()
  @download.to_s
end

#find_download(link_text = /Download/) ⇒ Object



41
42
43
44
45
# File 'lib/scrapers/imgur.rb', line 41

def find_download(link_text=/Download/)
  link = @page.link_with(:text => link_text)
  raise "#{link_text} not found on #{@page.uri.to_s}" if link.nil?
  @download.path = link.href
end

#make_url(imgur_code) ⇒ Object



33
34
35
# File 'lib/scrapers/imgur.rb', line 33

def make_url(imgur_code)
  @url.path = "/#{imgur_code}"
end

#retrieve_pageObject



37
38
39
# File 'lib/scrapers/imgur.rb', line 37

def retrieve_page()
  @page = @agent.get(@url.to_s)
end