Class: Rotten_tomatoes::Person
- Inherits:
-
Object
- Object
- Rotten_tomatoes::Person
- Defined in:
- lib/rotten-tomatoes.rb
Instance Attribute Summary collapse
-
#age ⇒ Object
readonly
Returns the value of attribute age.
-
#bio ⇒ Object
readonly
Returns the value of attribute bio.
-
#birthdate ⇒ Object
readonly
Returns the value of attribute birthdate.
-
#birthplace ⇒ Object
readonly
Returns the value of attribute birthplace.
-
#box_office ⇒ Object
readonly
Returns the value of attribute box_office.
-
#highest_rated ⇒ Object
readonly
Returns the value of attribute highest_rated.
-
#lowest_rated ⇒ Object
readonly
Returns the value of attribute lowest_rated.
-
#main_role ⇒ Object
readonly
Returns the value of attribute main_role.
-
#movies ⇒ Object
readonly
Returns the value of attribute movies.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#number_of_movies ⇒ Object
readonly
Returns the value of attribute number_of_movies.
-
#picture ⇒ Object
readonly
Returns the value of attribute picture.
Instance Method Summary collapse
-
#initialize(person_url) ⇒ Person
constructor
A new instance of Person.
- #set_age ⇒ Object
- #set_bio ⇒ Object
- #set_birthdate ⇒ Object
- #set_birthplace ⇒ Object
- #set_box_office ⇒ Object
- #set_highest_rated ⇒ Object
- #set_lowest_rated ⇒ Object
- #set_main_role ⇒ Object
- #set_movies ⇒ Object
- #set_name ⇒ Object
- #set_number_of_movies ⇒ Object
- #set_picture ⇒ Object
Constructor Details
#initialize(person_url) ⇒ Person
Returns a new instance of Person.
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/rotten-tomatoes.rb', line 218 def initialize person_url @info_page = Nokogiri::HTML(open(URI.parse(Rotten_tomatoes::Base_url + person_url + '?items=999'))) if @info_page set_movies set_name set_main_role set_picture set_highest_rated set_lowest_rated set_birthdate set_birthplace set_age set_bio set_number_of_movies set_box_office end @info_page = nil return self end |
Instance Attribute Details
#age ⇒ Object (readonly)
Returns the value of attribute age.
216 217 218 |
# File 'lib/rotten-tomatoes.rb', line 216 def age @age end |
#bio ⇒ Object (readonly)
Returns the value of attribute bio.
216 217 218 |
# File 'lib/rotten-tomatoes.rb', line 216 def bio @bio end |
#birthdate ⇒ Object (readonly)
Returns the value of attribute birthdate.
216 217 218 |
# File 'lib/rotten-tomatoes.rb', line 216 def birthdate @birthdate end |
#birthplace ⇒ Object (readonly)
Returns the value of attribute birthplace.
216 217 218 |
# File 'lib/rotten-tomatoes.rb', line 216 def birthplace @birthplace end |
#box_office ⇒ Object (readonly)
Returns the value of attribute box_office.
216 217 218 |
# File 'lib/rotten-tomatoes.rb', line 216 def box_office @box_office end |
#highest_rated ⇒ Object (readonly)
Returns the value of attribute highest_rated.
216 217 218 |
# File 'lib/rotten-tomatoes.rb', line 216 def highest_rated @highest_rated end |
#lowest_rated ⇒ Object (readonly)
Returns the value of attribute lowest_rated.
216 217 218 |
# File 'lib/rotten-tomatoes.rb', line 216 def lowest_rated @lowest_rated end |
#main_role ⇒ Object (readonly)
Returns the value of attribute main_role.
216 217 218 |
# File 'lib/rotten-tomatoes.rb', line 216 def main_role @main_role end |
#movies ⇒ Object (readonly)
Returns the value of attribute movies.
216 217 218 |
# File 'lib/rotten-tomatoes.rb', line 216 def movies @movies end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
216 217 218 |
# File 'lib/rotten-tomatoes.rb', line 216 def name @name end |
#number_of_movies ⇒ Object (readonly)
Returns the value of attribute number_of_movies.
216 217 218 |
# File 'lib/rotten-tomatoes.rb', line 216 def number_of_movies @number_of_movies end |
#picture ⇒ Object (readonly)
Returns the value of attribute picture.
216 217 218 |
# File 'lib/rotten-tomatoes.rb', line 216 def picture @picture end |
Instance Method Details
#set_age ⇒ Object
269 270 271 |
# File 'lib/rotten-tomatoes.rb', line 269 def set_age @age = ((Time.now - @birthdate) / 60 / 60 / 24 / 365).floor end |
#set_bio ⇒ Object
273 274 275 |
# File 'lib/rotten-tomatoes.rb', line 273 def set_bio @bio = @info_page.css('#celeb_bio p:nth-of-type(3)').text.split("Bio:").last.gsub('[More...]', '').strip end |
#set_birthdate ⇒ Object
261 262 263 |
# File 'lib/rotten-tomatoes.rb', line 261 def set_birthdate @birthdate = Time.parse @info_page.css('#celeb_bio p:first').text.split("Birthdate: ").last.strip end |
#set_birthplace ⇒ Object
265 266 267 |
# File 'lib/rotten-tomatoes.rb', line 265 def set_birthplace @birthplace = @info_page.css('#celeb_bio p:nth-of-type(2)').text.split("Birthplace: ").last.strip end |
#set_box_office ⇒ Object
281 282 283 |
# File 'lib/rotten-tomatoes.rb', line 281 def set_box_office @box_office = @info_page.css('#celeb_stats div.celeb_stat.last').text.split(":").last.strip end |
#set_highest_rated ⇒ Object
251 252 253 254 |
# File 'lib/rotten-tomatoes.rb', line 251 def set_highest_rated highest_rated_url = @info_page.css('#celebRatings p:first a').attribute('href').value @highest_rated = @movies[@movies.index {|movie| movie[:movie_url] == highest_rated_url}] end |
#set_lowest_rated ⇒ Object
256 257 258 259 |
# File 'lib/rotten-tomatoes.rb', line 256 def set_lowest_rated lowest_rated_url = @info_page.css('#celebRatings p:nth-of-type(2) a').attribute('href').value @lowest_rated = @movies[@movies.index {|movies| movies[:movie_url] == lowest_rated_url}] end |
#set_main_role ⇒ Object
243 244 245 |
# File 'lib/rotten-tomatoes.rb', line 243 def set_main_role @main_role = @info_page.css('#breadcrumb .subLevelCrumb').text.gsub('/', '').chomp('s') end |
#set_movies ⇒ Object
285 286 287 288 289 290 291 292 293 294 |
# File 'lib/rotten-tomatoes.rb', line 285 def set_movies @movies = [] @info_page.css('#filmographyTbl tbody tr').each do |movie| @movies.push({ :title => movie.css('.filmographyTbl_titleCol').text.strip, :movie_url => movie.css('.filmographyTbl_titleCol a').attribute('href').value, :credit => movie.css('.filmographyTbl_creditCol').text.strip }) end end |
#set_name ⇒ Object
239 240 241 |
# File 'lib/rotten-tomatoes.rb', line 239 def set_name @name = @info_page.css('h1.celeb_title').text end |
#set_number_of_movies ⇒ Object
277 278 279 |
# File 'lib/rotten-tomatoes.rb', line 277 def set_number_of_movies @number_of_movies = @movies.size end |
#set_picture ⇒ Object
247 248 249 |
# File 'lib/rotten-tomatoes.rb', line 247 def set_picture @picture = @info_page.css('#mainImage').attribute('src').value end |