Class: Headlines
- Inherits:
-
Object
- Object
- Headlines
- Defined in:
- lib/times-terminal.rb
Instance Attribute Summary collapse
-
#doc ⇒ Object
Returns the value of attribute doc.
-
#list ⇒ Object
Returns the value of attribute list.
Instance Method Summary collapse
- #call ⇒ Object
- #headlines ⇒ Object
-
#initialize ⇒ Headlines
constructor
A new instance of Headlines.
- #open_story(index) ⇒ Object
Constructor Details
#initialize ⇒ Headlines
Returns a new instance of Headlines.
8 9 10 11 |
# File 'lib/times-terminal.rb', line 8 def initialize @doc = Nokogiri::HTML(open("http://www.nytimes.com/pages/todayspaper/index.html")) @list = @doc.css("div.first h3 a") end |
Instance Attribute Details
#doc ⇒ Object
Returns the value of attribute doc.
6 7 8 |
# File 'lib/times-terminal.rb', line 6 def doc @doc end |
#list ⇒ Object
Returns the value of attribute list.
6 7 8 |
# File 'lib/times-terminal.rb', line 6 def list @list end |
Instance Method Details
#call ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/times-terminal.rb', line 24 def call puts "TODAY'S NEW YORK TIMES HEADLINES" headlines puts "\nWould you like to open a story? (Enter index)" i = gets.strip open_story(i) end |
#headlines ⇒ Object
13 14 15 |
# File 'lib/times-terminal.rb', line 13 def headlines @list.each_with_index { |story, i| puts "#{i+1}. #{story.text.strip}" } end |
#open_story(index) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/times-terminal.rb', line 17 def open_story(index) if index.to_i > 0 && index.to_i <= list.length link = list[index.to_i-1].attribute("href").value system "open #{link}" end end |