Class: IMDB

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#docObject

Returns the value of attribute doc.



8
9
10
# File 'lib/imdb.rb', line 8

def doc
  @doc
end

#idObject

Returns the value of attribute id.



8
9
10
# File 'lib/imdb.rb', line 8

def id
  @id
end

Returns the value of attribute link.



8
9
10
# File 'lib/imdb.rb', line 8

def link
  @link
end

Instance Method Details

#nameObject



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

#scoreObject



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

#yearObject



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