Class: Ngphoto
- Inherits:
-
Object
- Object
- Ngphoto
- Defined in:
- lib/ngphoto.rb
Constant Summary collapse
- NG_PHOTO_OF_THE_DAY_URL =
"http://photography.nationalgeographic.com/photography/photo-of-the-day/"
Instance Attribute Summary collapse
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(title, url) ⇒ Ngphoto
constructor
A new instance of Ngphoto.
- #save ⇒ Object
Constructor Details
#initialize(title, url) ⇒ Ngphoto
Returns a new instance of Ngphoto.
10 11 12 13 |
# File 'lib/ngphoto.rb', line 10 def initialize(title, url) @title = Time.now.strftime('%Y-%m-%d-') + title.split('--')[0].strip.gsub(' ', '-').downcase @url = url end |
Instance Attribute Details
#title ⇒ Object (readonly)
Returns the value of attribute title.
8 9 10 |
# File 'lib/ngphoto.rb', line 8 def title @title end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
8 9 10 |
# File 'lib/ngphoto.rb', line 8 def url @url end |
Class Method Details
.fetch ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/ngphoto.rb', line 19 def self.fetch doc = Nokogiri::HTML(open(NG_PHOTO_OF_THE_DAY_URL)) title = doc.css('title').first.text url = doc.css('.download_link a').first[:href] Ngphoto.new title, url end |
Instance Method Details
#save ⇒ Object
15 16 17 |
# File 'lib/ngphoto.rb', line 15 def save system "curl -o ~/Pictures/ngphoto/#{title}.jpg #{url}" end |