Class: TedTalks::Info

Inherits:
Object
  • Object
show all
Defined in:
lib/ted_talks/talk_info.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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, author=nil, description=nil, time=nil, date=nil, views=nil)
    @title = title
    @author = author
    @description = description
    @time = time
    @date = date
    @@views = views
end

Instance Attribute Details

#authorObject

Returns the value of attribute author.



3
4
5
# File 'lib/ted_talks/talk_info.rb', line 3

def author
  @author
end

#dateObject

Returns the value of attribute date.



3
4
5
# File 'lib/ted_talks/talk_info.rb', line 3

def date
  @date
end

#descriptionObject

Returns the value of attribute description.



3
4
5
# File 'lib/ted_talks/talk_info.rb', line 3

def description
  @description
end

#timeObject

Returns the value of attribute time.



3
4
5
# File 'lib/ted_talks/talk_info.rb', line 3

def time
  @time
end

#titleObject

Returns the value of attribute title.



3
4
5
# File 'lib/ted_talks/talk_info.rb', line 3

def title
  @title
end

#viewsObject

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))

author = 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.author = author.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