Class: TedTalks::Talk

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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, author=nil, date=nil, rating=nil, url=nil)
   @title = title
   @author = author
   @date = date
   @rating = rating
   @@url = url
end

Instance Attribute Details

#authorObject

Returns the value of attribute author.



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

def author
  @author
end

#dateObject

Returns the value of attribute date.



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

def date
  @date
end

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#ratingObject

Returns the value of attribute rating.



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

def rating
  @rating
end

#timeObject

Returns the value of attribute time.



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

def time
  @time
end

#titleObject

Returns the value of attribute title.



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

def title
  @title
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

#viewsObject

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")
	author = doc.css(".media__message").css("h4.h12")
	date = doc.css(".media__message").css(".meta").css(".meta__item").css("span.meta__val")
	rating = 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.author = author[i].text if author[i] != nil
		talk.date = date[i].text.strip! if date[i] != nil
		talk.rating = rating[i].text.strip! if rating[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