Class: Rotten_tomatoes::Person

Inherits:
Object
  • Object
show all
Defined in:
lib/rotten-tomatoes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#ageObject (readonly)

Returns the value of attribute age.



216
217
218
# File 'lib/rotten-tomatoes.rb', line 216

def age
  @age
end

#bioObject (readonly)

Returns the value of attribute bio.



216
217
218
# File 'lib/rotten-tomatoes.rb', line 216

def bio
  @bio
end

#birthdateObject (readonly)

Returns the value of attribute birthdate.



216
217
218
# File 'lib/rotten-tomatoes.rb', line 216

def birthdate
  @birthdate
end

#birthplaceObject (readonly)

Returns the value of attribute birthplace.



216
217
218
# File 'lib/rotten-tomatoes.rb', line 216

def birthplace
  @birthplace
end

#box_officeObject (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_ratedObject (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_ratedObject (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_roleObject (readonly)

Returns the value of attribute main_role.



216
217
218
# File 'lib/rotten-tomatoes.rb', line 216

def main_role
  @main_role
end

#moviesObject (readonly)

Returns the value of attribute movies.



216
217
218
# File 'lib/rotten-tomatoes.rb', line 216

def movies
  @movies
end

#nameObject (readonly)

Returns the value of attribute name.



216
217
218
# File 'lib/rotten-tomatoes.rb', line 216

def name
  @name
end

#number_of_moviesObject (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

#pictureObject (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_ageObject



269
270
271
# File 'lib/rotten-tomatoes.rb', line 269

def set_age
  @age = ((Time.now - @birthdate) / 60 / 60 / 24 / 365).floor
end

#set_bioObject



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_birthdateObject



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_birthplaceObject



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_officeObject



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_ratedObject



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_ratedObject



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_roleObject



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_moviesObject



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_nameObject



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_moviesObject



277
278
279
# File 'lib/rotten-tomatoes.rb', line 277

def set_number_of_movies
  @number_of_movies = @movies.size
end

#set_pictureObject



247
248
249
# File 'lib/rotten-tomatoes.rb', line 247

def set_picture
  @picture = @info_page.css('#mainImage').attribute('src').value
end