Class: Kinopoisk::Movie

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, title = nil) ⇒ Movie

New instance can be initialized with id(integer) or title(string). Second argument may also receive a string title to make it easier to differentiate Kinopoisk::Movie instances.

Kinopoisk::Movie.new 277537
Kinopoisk::Movie.new 'Dexter'

Initializing by title would send a search request and return first match. Movie page request is made once and on the first access to a remote data.



16
17
18
19
20
# File 'lib/kinopoisk/movie.rb', line 16

def initialize(input, title=nil)
  @id    = input.is_a?(String) ? find_id_by_title(input) : input
  @url   = "https://www.kinopoisk.ru/film/#{id}/"
  @title = title
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#titleObject

Returns a string containing title in russian



29
30
31
# File 'lib/kinopoisk/movie.rb', line 29

def title
  @title
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

Instance Method Details

#actorsObject

Returns an array of strings containing actor names



23
24
25
26
# File 'lib/kinopoisk/movie.rb', line 23

def actors
  doc.search('#actorList ul li a').map{|n| n.text.gsub("\n",'').strip}
    .delete_if{|text| text=='...'}
end

#art_directorsObject

Returns an array of strings containing art director names



149
150
151
# File 'lib/kinopoisk/movie.rb', line 149

def art_directors
  to_array search_by_text 'художник'
end

#box_office_ruObject

Returns a string containing Russia box-office



59
60
61
# File 'lib/kinopoisk/movie.rb', line 59

def box_office_ru
  doc.search("td#div_rus_box_td2 a").text
end

#box_office_usObject

Returns a string containing USA box-office



64
65
66
# File 'lib/kinopoisk/movie.rb', line 64

def box_office_us
  doc.search("td#div_usa_box_td2 a").text
end

#box_office_worldObject

Returns a string containing world box-office



69
70
71
# File 'lib/kinopoisk/movie.rb', line 69

def box_office_world
  doc.search("td#div_world_box_td2 a").text
end

#budgetObject

Returns a string containing budget for the movie



54
55
56
# File 'lib/kinopoisk/movie.rb', line 54

def budget
  doc.search("//td[text()='бюджет']/following-sibling::*//a").text
end

#composersObject

Returns an array of strings containing composer names



129
130
131
# File 'lib/kinopoisk/movie.rb', line 129

def composers
  to_array search_by_itemprop 'musicBy'
end

#countriesObject

Returns an array of strings containing countries



49
50
51
# File 'lib/kinopoisk/movie.rb', line 49

def countries
  doc.search("table.info a[href*='/m_act%5Bcountry%5D/']").map(&:text)
end

#descriptionObject

Returns a string containing movie description



109
110
111
# File 'lib/kinopoisk/movie.rb', line 109

def description
  search_by_itemprop 'description'
end

#directorsObject

Returns an array of strings containing director names



119
120
121
# File 'lib/kinopoisk/movie.rb', line 119

def directors
  to_array search_by_itemprop 'director'
end

#durationObject

Returns a string containing duration of the film



169
170
171
# File 'lib/kinopoisk/movie.rb', line 169

def duration
  search_by_text('время').strip
end

#editorsObject

Returns an array of strings containing editor names



154
155
156
# File 'lib/kinopoisk/movie.rb', line 154

def editors
  to_array search_by_text 'монтаж'
end

#genresObject

Returns an array of strings containing genres



134
135
136
# File 'lib/kinopoisk/movie.rb', line 134

def genres
  to_array search_by_itemprop 'genre'
end

#imdb_ratingObject

Returns a float imdb rating



39
40
41
# File 'lib/kinopoisk/movie.rb', line 39

def imdb_rating
  doc.search('div.block_2 div:eq(2)').text[/\d.\d\d/].to_f
end

#imdb_rating_countObject

Returns an integer imdb rating vote count



34
35
36
# File 'lib/kinopoisk/movie.rb', line 34

def imdb_rating_count
  doc.search('div.block_2 div:eq(2)').text.gsub(/.*\(/, '').gsub(/[ ()]/, '').to_i
end

#lengthObject

Returns an integer length of the movie in minutes



99
100
101
# File 'lib/kinopoisk/movie.rb', line 99

def length
  doc.search('td#runtime').text.to_i
end

#minimal_ageObject

Returns a string containing minimal age



164
165
166
# File 'lib/kinopoisk/movie.rb', line 164

def minimal_age
  search_by_text('возраст').strip
end

#operatorsObject

Returns an array of strings containing operator names



144
145
146
# File 'lib/kinopoisk/movie.rb', line 144

def operators
  to_array search_by_text 'оператор'
end

#posterObject

Returns a url to a small sized poster



74
75
76
# File 'lib/kinopoisk/movie.rb', line 74

def poster
  doc.search(".film-img-box img[itemprop='image']").first.attr 'src'
end

#poster_bigObject

Returns a url to a big sized poster



94
95
96
# File 'lib/kinopoisk/movie.rb', line 94

def poster_big
  poster.gsub 'iphone/iphone360_', 'big/'
end

#premiere_ruObject

Returns a string containing Russian premiere date



84
85
86
# File 'lib/kinopoisk/movie.rb', line 84

def premiere_ru
  doc.search('td#div_rus_prem_td2 a:first').text
end

#premiere_worldObject

Returns a string containing world premiere date



79
80
81
# File 'lib/kinopoisk/movie.rb', line 79

def premiere_world
  doc.search('td#div_world_prem_td2 a:first').text
end

#producersObject

Returns an array of strings containing producer names



124
125
126
# File 'lib/kinopoisk/movie.rb', line 124

def producers
  to_array search_by_itemprop 'producer'
end

#ratingObject

Returns a float kinopoisk rating



89
90
91
# File 'lib/kinopoisk/movie.rb', line 89

def rating
  doc.search('span.rating_ball').text.to_f
end

#rating_countObject

Returns an integer kinopoisk rating vote count



114
115
116
# File 'lib/kinopoisk/movie.rb', line 114

def rating_count
  search_by_itemprop('ratingCount').gsub(' ', '').to_i
end

#sloganObject

Returns a string containing movie slogan



159
160
161
# File 'lib/kinopoisk/movie.rb', line 159

def slogan
  search_by_text 'слоган'
end

#title_enObject

Returns a string containing title in english



104
105
106
# File 'lib/kinopoisk/movie.rb', line 104

def title_en
  search_by_itemprop 'alternativeHeadline'
end

#writersObject

Returns an array of strings containing writer names



139
140
141
# File 'lib/kinopoisk/movie.rb', line 139

def writers
  to_array search_by_text 'сценарий'
end

#yearObject

Returns an integer release year



44
45
46
# File 'lib/kinopoisk/movie.rb', line 44

def year
  doc.search("table.info a[href*='/m_act%5Byear%5D/']").text.to_i
end