Class: Spotlite::Person
- Inherits:
-
Object
- Object
- Spotlite::Person
- Defined in:
- lib/spotlite/person.rb
Overview
Represent a person on IMDb.com
Instance Attribute Summary collapse
-
#imdb_id ⇒ Object
Returns the value of attribute imdb_id.
-
#name ⇒ Object
Returns name as a string.
Instance Method Summary collapse
-
#birth_date ⇒ Object
Returns birth date as a date.
-
#birth_name ⇒ Object
Returns name at birth as a string.
-
#death_date ⇒ Object
Returns death date as a date.
-
#initialize(imdb_id, name = nil) ⇒ Person
constructor
Initialize a new person object by its IMDb ID as a string.
-
#photo_url ⇒ Object
Returns primary photo URL as a string.
Constructor Details
#initialize(imdb_id, name = nil) ⇒ Person
Initialize a new person object by its IMDb ID as a string
person = Spotlite::Person.new("0005132")
Spotlite::Person class objects are lazy loading. No HTTP request will be performed upon object initialization. HTTP request will be performed once when you use a method that needs remote data
14 15 16 17 18 |
# File 'lib/spotlite/person.rb', line 14 def initialize(imdb_id, name = nil) @imdb_id = imdb_id @name = name @url = "http://www.imdb.com/name/nm#{imdb_id}" end |
Instance Attribute Details
#imdb_id ⇒ Object
Returns the value of attribute imdb_id.
5 6 7 |
# File 'lib/spotlite/person.rb', line 5 def imdb_id @imdb_id end |
#name ⇒ Object
Returns name as a string
21 22 23 |
# File 'lib/spotlite/person.rb', line 21 def name @name end |
Instance Method Details
#birth_date ⇒ Object
Returns birth date as a date
31 32 33 |
# File 'lib/spotlite/person.rb', line 31 def birth_date details.at("time[itemprop='birthDate']")["datetime"].parse_date rescue nil end |
#birth_name ⇒ Object
Returns name at birth as a string
26 27 28 |
# File 'lib/spotlite/person.rb', line 26 def birth_name details.at("#overview-top .txt-block a[href='bio']").text.strip rescue nil end |
#death_date ⇒ Object
Returns death date as a date
36 37 38 |
# File 'lib/spotlite/person.rb', line 36 def death_date details.at("time[itemprop='deathDate']")["datetime"].parse_date rescue nil end |
#photo_url ⇒ Object
Returns primary photo URL as a string
41 42 43 44 45 46 47 |
# File 'lib/spotlite/person.rb', line 41 def photo_url src = details.at("#img_primary img")["src"] rescue nil if src =~ /^(http:.+@@)/ || src =~ /^(http:.+?)\.[^\/]+$/ $1 + ".jpg" end end |