Class: NgpodScraper::PhotoPage
- Inherits:
-
Object
- Object
- NgpodScraper::PhotoPage
- Defined in:
- lib/ngpod_scraper/photo_page.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(url, config = {}) ⇒ PhotoPage
constructor
A new instance of PhotoPage.
- #photo ⇒ Object
- #photo_url ⇒ Object
Constructor Details
#initialize(url, config = {}) ⇒ PhotoPage
Returns a new instance of PhotoPage.
5 6 7 8 |
# File 'lib/ngpod_scraper/photo_page.rb', line 5 def initialize(url, config = {}) @url = url @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
3 4 5 |
# File 'lib/ngpod_scraper/photo_page.rb', line 3 def config @config end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
3 4 5 |
# File 'lib/ngpod_scraper/photo_page.rb', line 3 def url @url end |
Instance Method Details
#photo ⇒ Object
10 11 12 13 14 |
# File 'lib/ngpod_scraper/photo_page.rb', line 10 def photo url = photo_url attributes = (config[:photo] || {}).merge(:url => url, :file => open(photo_url)) return Photo.new(attributes) end |
#photo_url ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/ngpod_scraper/photo_page.rb', line 16 def photo_url page = Nokogiri::HTML(open(url)) begin "http:#{page.search(".primary_photo img").attr('src').value}" rescue Exception => e raise MissingPhotoUrl, "Cannot find the photo url: #{e.message}" end end |