Class: Scrapers::Imgur
- Inherits:
-
Object
- Object
- Scrapers::Imgur
- Defined in:
- lib/scrapers/imgur.rb
Instance Attribute Summary collapse
-
#agent ⇒ Object
Returns the value of attribute agent.
-
#download ⇒ Object
Returns the value of attribute download.
-
#page ⇒ Object
Returns the value of attribute page.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #download_link(code) ⇒ Object
- #find_download(link_text = /Download/) ⇒ Object
-
#initialize ⇒ Imgur
constructor
A new instance of Imgur.
- #make_url(imgur_code) ⇒ Object
- #retrieve_page ⇒ Object
Constructor Details
#initialize ⇒ Imgur
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
#agent ⇒ Object
Returns the value of attribute agent.
18 19 20 |
# File 'lib/scrapers/imgur.rb', line 18 def agent @agent end |
#download ⇒ Object
Returns the value of attribute download.
18 19 20 |
# File 'lib/scrapers/imgur.rb', line 18 def download @download end |
#page ⇒ Object
Returns the value of attribute page.
18 19 20 |
# File 'lib/scrapers/imgur.rb', line 18 def page @page end |
#url ⇒ Object
Returns the value of attribute url.
18 19 20 |
# File 'lib/scrapers/imgur.rb', line 18 def url @url end |
Instance Method Details
#download_link(code) ⇒ Object
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_page ⇒ Object
37 38 39 |
# File 'lib/scrapers/imgur.rb', line 37 def retrieve_page() @page = @agent.get(@url.to_s) end |