Class: TedTalks::Info
- Inherits:
-
Object
- Object
- TedTalks::Info
- Defined in:
- lib/ted_talks/talk_info.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.
-
#time ⇒ Object
Returns the value of attribute time.
-
#title ⇒ Object
Returns the value of attribute title.
-
#views ⇒ Object
Returns the value of attribute views.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(title = nil, author = nil, description = nil, time = nil, date = nil, views = nil) ⇒ Info
constructor
A new instance of Info.
Constructor Details
#initialize(title = nil, author = nil, description = nil, time = nil, date = nil, views = nil) ⇒ Info
Returns a new instance of Info.
5 6 7 8 9 10 11 12 |
# File 'lib/ted_talks/talk_info.rb', line 5 def initialize(title=nil, =nil, description=nil, time=nil, date=nil, views=nil) @title = title @author = @description = description @time = time @date = date @@views = views end |
Instance Attribute Details
#author ⇒ Object
Returns the value of attribute author.
3 4 5 |
# File 'lib/ted_talks/talk_info.rb', line 3 def @author end |
#date ⇒ Object
Returns the value of attribute date.
3 4 5 |
# File 'lib/ted_talks/talk_info.rb', line 3 def date @date end |
#description ⇒ Object
Returns the value of attribute description.
3 4 5 |
# File 'lib/ted_talks/talk_info.rb', line 3 def description @description end |
#time ⇒ Object
Returns the value of attribute time.
3 4 5 |
# File 'lib/ted_talks/talk_info.rb', line 3 def time @time end |
#title ⇒ Object
Returns the value of attribute title.
3 4 5 |
# File 'lib/ted_talks/talk_info.rb', line 3 def title @title end |
#views ⇒ Object
Returns the value of attribute views.
3 4 5 |
# File 'lib/ted_talks/talk_info.rb', line 3 def views @views end |
Class Method Details
.talk_info(url = 'http://www.ted.com/talks') ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ted_talks/talk_info.rb', line 14 def self.talk_info(url='http://www.ted.com/talks') doc = Nokogiri::HTML(open(url)) = doc.search("div.player-hero__speaker").search("span.player-hero__speaker__content") title = doc.search("div.player-hero__title").search("span.player-hero__title__content") description = doc.search(".talk-subsection").search(".talk-top__details").search("p.talk-description") time = doc.search("div.player-hero__meta").search("span") date = doc.search("div.player-hero__meta").search("span") views = doc.search("div.talk-sharing__count").search("span.talk-sharing__value") talk_info = self.new talk_info. = .text talk_info.title = title.text talk_info.description = description.text talk_info.time = time[0].text talk_info.date = date[1].text talk_info.views = views.text.strip! talk_info end |