Class: Apod
- Inherits:
-
Object
- Object
- Apod
- Defined in:
- lib/apod.rb,
lib/apod/version.rb
Constant Summary collapse
- VERSION =
"0.2.0"
Instance Attribute Summary collapse
-
#pictures ⇒ Object
readonly
Returns the value of attribute pictures.
Instance Method Summary collapse
-
#initialize ⇒ Apod
constructor
A new instance of Apod.
- #search(query) ⇒ Object
- #titles ⇒ Object
Constructor Details
#initialize ⇒ Apod
9 10 11 12 13 14 15 16 17 |
# File 'lib/apod.rb', line 9 def initialize @pictures = [] page = Nokogiri::HTML(open("http://apod.nasa.gov/apod/archivepix.html")) pics = page.css('b a') pics.each do |pic| @pictures << Pic.new(pic.text, "http://apod.nasa.gov/apod/" + pic["href"]) end end |
Instance Attribute Details
#pictures ⇒ Object (readonly)
Returns the value of attribute pictures.
7 8 9 |
# File 'lib/apod.rb', line 7 def pictures @pictures end |
Instance Method Details
#search(query) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/apod.rb', line 23 def search(query) @pictures = [] if query.size > 60 return "ERROR: Query must be less than 60 characters" end clnt = HTTPClient.new("http://apod.nasa.gov/cgi-bin/apod/apod_search") res = clnt.post('http://apod.nasa.gov/cgi-bin/apod/apod_search', {'tquery' => query}).content page = Nokogiri::HTML(res) page.css('body > p > a:nth-child(2)').each do |elem| @pictures << Pic.new(elem.text, elem["href"]) end @pictures end |
#titles ⇒ Object
19 20 21 |
# File 'lib/apod.rb', line 19 def titles @pictures.collect{ |pic| pic.title } end |