Class: Kinopoisk::Person

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, name = nil) ⇒ Person

New instance can be initialized with id(string or integer) and an optional name to make it easier to differentiate Kinopoisk::Person instances.

Kinopoisk::Person.new 13180

Request to kinopoisk is made once and on the first access to a remote data.



13
14
15
16
17
# File 'lib/kinopoisk/person.rb', line 13

def initialize(id, name=nil)
  @id   = id
  @url  = "https://www.kinopoisk.ru/name/#{id}/"
  @name = name
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/kinopoisk/person.rb', line 4

def id
  @id
end

#nameObject

Returns a string containing name in russian



25
26
27
# File 'lib/kinopoisk/person.rb', line 25

def name
  @name
end

#urlObject

Returns the value of attribute url.



4
5
6
# File 'lib/kinopoisk/person.rb', line 4

def url
  @url
end

Instance Method Details

#best_moviesObject

Returns an array of strings containing best movie titles



65
66
67
# File 'lib/kinopoisk/person.rb', line 65

def best_movies
  doc.search('#BestFilmList a').map(&:text)
end

#birthdateObject

Returns a birthdate date object



40
41
42
# File 'lib/kinopoisk/person.rb', line 40

def birthdate
  Date.strptime doc.search("td.birth").first.attr 'birthdate'
end

#birthplaceObject

Returns a string containing birthplace



45
46
47
# File 'lib/kinopoisk/person.rb', line 45

def birthplace
  search_by_text('место рождения').split(', ').first
end

#careerObject

Returns an array of strings containing career professions



55
56
57
# File 'lib/kinopoisk/person.rb', line 55

def career
  search_by_text('карьера').split(', ')
end

#first_movieObject

Returns a string containing year of first movie



70
71
72
# File 'lib/kinopoisk/person.rb', line 70

def first_movie
  doc.search("a[title='Первый фильм']").text
end

#genresObject

Returns an array of strings containing genres



50
51
52
# File 'lib/kinopoisk/person.rb', line 50

def genres
  search_by_text('жанры').split(', ')
end

#heightObject

Returns a string containing height



80
81
82
# File 'lib/kinopoisk/person.rb', line 80

def height
  search_by_text 'рост'
end

#last_movieObject

Returns a string containing year of last movie



75
76
77
# File 'lib/kinopoisk/person.rb', line 75

def last_movie
  doc.search("a[title='Последний фильм']").text
end

#name_enObject

Returns a string containing name in english



30
31
32
# File 'lib/kinopoisk/person.rb', line 30

def name_en
  doc.search("#headerPeople span[itemprop='alternativeHeadline']").text.strip
end

#partnerObject

Returns a string containing partner’s name



35
36
37
# File 'lib/kinopoisk/person.rb', line 35

def partner
  doc.search("//td[@class='type'][contains(text(),'супруг')]/following-sibling::*").text
end

#posterObject

Returns a url to a poster



20
21
22
# File 'lib/kinopoisk/person.rb', line 20

def poster
  doc.search(".film-img-box img").first.attr 'src'
end

#total_moviesObject

Returns an integer total movie count



60
61
62
# File 'lib/kinopoisk/person.rb', line 60

def total_movies
  search_by_text('всего фильмов').to_i
end