Class: IMDB
- Inherits:
-
Object
- Object
- IMDB
- Defined in:
- lib/imdb.rb
Instance Attribute Summary collapse
-
#doc ⇒ Object
Returns the value of attribute doc.
-
#id ⇒ Object
Returns the value of attribute id.
-
#link ⇒ Object
Returns the value of attribute link.
Instance Method Summary collapse
-
#initialize(name, year = nil, link = nil) ⇒ IMDB
constructor
A new instance of IMDB.
- #name ⇒ Object
- #score ⇒ Object
- #year ⇒ Object
Constructor Details
#initialize(name, year = nil, link = nil) ⇒ IMDB
Returns a new instance of IMDB.
10 11 12 13 14 15 16 17 |
# File 'lib/imdb.rb', line 10 def initialize(name, year = nil, link = nil) # $stdout.print 'i' @try = 3 @name, @year, @link = name, year, link @coder = HTMLEntities.new set_doc set_id end |
Instance Attribute Details
#doc ⇒ Object
Returns the value of attribute doc.
8 9 10 |
# File 'lib/imdb.rb', line 8 def doc @doc end |
#id ⇒ Object
Returns the value of attribute id.
8 9 10 |
# File 'lib/imdb.rb', line 8 def id @id end |
#link ⇒ Object
Returns the value of attribute link.
8 9 10 |
# File 'lib/imdb.rb', line 8 def link @link end |
Instance Method Details
#name ⇒ Object
31 32 33 34 |
# File 'lib/imdb.rb', line 31 def name $KCODE = 'utf-8' @doc ? @coder.decode(@doc.search("title").inner_html.match(/(.*)\s\(/u)[1]) : @name end |
#score ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/imdb.rb', line 19 def score if @doc && score_text = @doc.search("div.meta b").first score_text.inner_html.match(/(.*)\/10/)[1].to_f else 0 end end |
#year ⇒ Object
27 28 29 |
# File 'lib/imdb.rb', line 27 def year @doc ? @doc.search("title").inner_html.match(/\s\(([0-9]{4})/)[1].to_i : @year.to_i end |