Class: IMDB::Data::Credit

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

Constant Summary

Constants included from REGEXP::HTML

REGEXP::HTML::BILLBOARD, REGEXP::HTML::BR, REGEXP::HTML::CH, REGEXP::HTML::CHAR_CREDIT, REGEXP::HTML::DIV_ID_FOOTER, REGEXP::HTML::DIV_ID_PAGECONTENT, REGEXP::HTML::IN_PARENS, REGEXP::HTML::LINK, REGEXP::HTML::LINK_PLUS_PARENS, REGEXP::HTML::LINK_REL_CANONICAL, REGEXP::HTML::META_CONTENT_TYPE, REGEXP::HTML::NM, REGEXP::HTML::SPLIT_BEFORE_PAREN, REGEXP::HTML::TD_CHAR, REGEXP::HTML::TD_DDD, REGEXP::HTML::TD_NM, REGEXP::HTML::TITLE, REGEXP::HTML::TT

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(noko_tr) ⇒ Credit

Returns a new instance of Credit.



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

def initialize noko_tr
  @tr = noko_tr
end

Instance Attribute Details

#trObject (readonly)

Returns the value of attribute tr.



9
10
11
# File 'lib/imdb-html/data/credit.rb', line 9

def tr
  @tr
end

Instance Method Details

#nameObject



11
12
13
# File 'lib/imdb-html/data/credit.rb', line 11

def name
  tr.at('td.nm').text
end

#nmObject



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

def nm
  tr.at('td.nm a')["href"][ NM ]
end

#rolesObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/imdb-html/data/credit.rb', line 17

def roles
  roles, parens = tr.at('td.char').inner_html.split( SPLIT_BEFORE_PAREN )
  roles = "" unless roles
  parens = "" unless parens

  etc = parens.scan( IN_PARENS ).flatten
  roles.split(" / ").map do |role|

    name_of_role = role.gsub(%r{<.*?>},"").strip
    role_ch = role[ CH ]

    hash = {:char => name_of_role}
    hash[:ch] = role_ch.to_i if role_ch
    etc.each{ |thing| hash[ thing.to_sym ] = true }
    hash
  end
end