Class: NgpodScraper::PhotoPage

Inherits:
Object
  • Object
show all
Defined in:
lib/ngpod_scraper/photo_page.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#configObject (readonly)

Returns the value of attribute config.



3
4
5
# File 'lib/ngpod_scraper/photo_page.rb', line 3

def config
  @config
end

#urlObject (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

#photoObject



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_urlObject



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