Class: IMDB::Data::Episode

Inherits:
Object
  • Object
show all
Includes:
REGEXP
Defined in:
lib/imdb-html/data/episode.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(noko_h4) ⇒ Episode

Returns a new instance of Episode.



14
15
16
# File 'lib/imdb-html/data/episode.rb', line 14

def initialize noko_h4
	@h4 = noko_h4
end

Instance Attribute Details

#h4Object (readonly)

Returns the value of attribute h4.



17
18
19
# File 'lib/imdb-html/data/episode.rb', line 17

def h4
  @h4
end

Class Method Details

.parse_params(noko_h4) ⇒ Object



6
7
8
9
10
# File 'lib/imdb-html/data/episode.rb', line 6

def self.parse_params noko_h4
	noko_h4.episodes_h4.map do |h4|
		self.new(h4).to_h
	end
end

Instance Method Details

#castObject



42
43
44
45
46
47
# File 'lib/imdb-html/data/episode.rb', line 42

def cast
	h4.next_element.next_element.next_element.next_element.cast.map do |elem|
		credit = IMDB::Data::Credit.new elem
		{:name => credit.name, :nm => credit.nm.nil? ? 0 : credit.nm.to_i, :roles => credit.roles}
	end rescue nil
end

#dateObject



36
37
38
# File 'lib/imdb-html/data/episode.rb', line 36

def date
	Date.parse h4.next_element.text
end

#descriptionObject



39
40
41
# File 'lib/imdb-html/data/episode.rb', line 39

def description
	h4.next_element.next_element.next.text
end

#episode_numberObject



23
24
25
26
# File 'lib/imdb-html/data/episode.rb', line 23

def episode_number
	num = h4.text[ CONTENT::EPISODE ]
	num ? num.rjust(2,'0') : "??"
end

#seObject



27
28
29
# File 'lib/imdb-html/data/episode.rb', line 27

def se
	["S", season_number, "E", episode_number].join
end

#season_numberObject



19
20
21
22
# File 'lib/imdb-html/data/episode.rb', line 19

def season_number
	num = h4.text[ CONTENT::SEASON ]
	num ? num.rjust(2,'0') : "??"
end

#titleObject



30
31
32
# File 'lib/imdb-html/data/episode.rb', line 30

def title
	h4.at('a').text
end

#to_hObject



48
49
50
51
52
53
54
55
# File 'lib/imdb-html/data/episode.rb', line 48

def to_h
	hash = {:se => se, :title => title}
	hash[:tt] = tt.to_i if tt
	hash[:air_date] = date
	hash[:description] = description.empty? ? nil : description
	hash[:cast] = cast
	hash
end

#ttObject



33
34
35
# File 'lib/imdb-html/data/episode.rb', line 33

def tt
	h4.at('a')["href"][ HTML::TT ]
end