Class: TedTalks::Talk
- Inherits:
-
Object
- Object
- TedTalks::Talk
- Defined in:
- lib/ted_talks/talk.rb
Instance Attribute Summary collapse
-
#author ⇒ Object
Returns the value of attribute author.
-
#date ⇒ Object
Returns the value of attribute date.
-
#description ⇒ Object
Returns the value of attribute description.
-
#rating ⇒ Object
Returns the value of attribute rating.
-
#time ⇒ Object
Returns the value of attribute time.
-
#title ⇒ Object
Returns the value of attribute title.
-
#url ⇒ Object
Returns the value of attribute url.
-
#views ⇒ Object
Returns the value of attribute views.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(title = nil, author = nil, date = nil, rating = nil, url = nil) ⇒ Talk
constructor
A new instance of Talk.
Constructor Details
#initialize(title = nil, author = nil, date = nil, rating = nil, url = nil) ⇒ Talk
Returns a new instance of Talk.
5 6 7 8 9 10 11 |
# File 'lib/ted_talks/talk.rb', line 5 def initialize(title=nil, =nil, date=nil, =nil, url=nil) @title = title @author = @date = date @rating = @@url = url end |
Instance Attribute Details
#author ⇒ Object
Returns the value of attribute author.
3 4 5 |
# File 'lib/ted_talks/talk.rb', line 3 def @author end |
#date ⇒ Object
Returns the value of attribute date.
3 4 5 |
# File 'lib/ted_talks/talk.rb', line 3 def date @date end |
#description ⇒ Object
Returns the value of attribute description.
3 4 5 |
# File 'lib/ted_talks/talk.rb', line 3 def description @description end |
#rating ⇒ Object
Returns the value of attribute rating.
3 4 5 |
# File 'lib/ted_talks/talk.rb', line 3 def @rating end |
#time ⇒ Object
Returns the value of attribute time.
3 4 5 |
# File 'lib/ted_talks/talk.rb', line 3 def time @time end |
#title ⇒ Object
Returns the value of attribute title.
3 4 5 |
# File 'lib/ted_talks/talk.rb', line 3 def title @title end |
#url ⇒ Object
Returns the value of attribute url.
3 4 5 |
# File 'lib/ted_talks/talk.rb', line 3 def url @url end |
#views ⇒ Object
Returns the value of attribute views.
3 4 5 |
# File 'lib/ted_talks/talk.rb', line 3 def views @views end |
Class Method Details
.top_talks(url = 'http://www.ted.com/talks') ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ted_talks/talk.rb', line 13 def self.top_talks(url='http://www.ted.com/talks') talk_array = [] doc = Nokogiri::HTML(open(url)) title = doc.css(".media__message").css("h4.h9").css("a") = doc.css(".media__message").css("h4.h12") date = doc.css(".media__message").css(".meta").css(".meta__item").css("span.meta__val") = doc.css(".media__message").css(".meta").css(".meta__row").css(".meta__val") url = doc.css("h4.h9").css("a") (0..9).each do |i| talk = self.new talk.title = title[i].text.strip! if title[i] != nil talk. = [i].text if [i] != nil talk.date = date[i].text.strip! if date[i] != nil talk. = [i].text.strip! if [i] != nil talk.url = "http://www.ted.com" + url[i].attr("href") if url[i] != nil talk_array << talk if talk.title != nil end talk_array end |