Class: ImdbCelebrity::Celebrity

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

Overview

Represents a celebrity on IMDB.com

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(imdb_id, title = nil, parser = "HpricotParser") ⇒ Celebrity

Initialize a new IMDB celebrity object with it’s IMDB id (as a String)

celebrity = Imdb::Celebrity.new("0095016", "celeb name", "Parsing Class")

Imdb::Celebrity objects are lazy loading, meaning that no HTTP request will be performed when a new object is created. Only when you use an accessor that needs the remote data, a HTTP request is made (once).



17
18
19
20
21
22
# File 'lib/imdb_celebrity/celebrity.rb', line 17

def initialize imdb_id, title = nil, parser = "HpricotParser"
  @id = imdb_id
  @url = "http://www.imdb.com/name/nm#{imdb_id}/bio"
  @name = title.gsub(/"/, "") if title
  @parser = initialize_parser parser
end

Instance Attribute Details

#biographyObject

Returns the value of attribute biography.



6
7
8
# File 'lib/imdb_celebrity/celebrity.rb', line 6

def biography
  @biography
end

#heightObject

Returns the value of attribute height.



6
7
8
# File 'lib/imdb_celebrity/celebrity.rb', line 6

def height
  @height
end

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/imdb_celebrity/celebrity.rb', line 6

def id
  @id
end

#name(flag = false) ⇒ Object

Returns the value of attribute name.



6
7
8
# File 'lib/imdb_celebrity/celebrity.rb', line 6

def name
  @name
end

#nationalityObject

Returns the value of attribute nationality.



6
7
8
# File 'lib/imdb_celebrity/celebrity.rb', line 6

def nationality
  @nationality
end

#parserObject

Returns the value of attribute parser.



6
7
8
# File 'lib/imdb_celebrity/celebrity.rb', line 6

def parser
  @parser
end

#real_nameObject

Returns the value of attribute real_name.



6
7
8
# File 'lib/imdb_celebrity/celebrity.rb', line 6

def real_name
  @real_name
end

#urlObject

Returns the value of attribute url.



6
7
8
# File 'lib/imdb_celebrity/celebrity.rb', line 6

def url
  @url
end

Instance Method Details

#celebrity_dataObject



52
53
54
55
56
57
58
# File 'lib/imdb_celebrity/celebrity.rb', line 52

def celebrity_data
  @real_name ||=@parser.real_name
  @biography ||= @parser.biography
  @height ||= @parser.height
  @nationality ||= @parser.nationality
  return true
end

#to_sObject



24
25
26
# File 'lib/imdb_celebrity/celebrity.rb', line 24

def to_s
  [@id, @url, @name, @real_name, @biography, @height, @nationality]
end