Class: Kinopoisk::Movie
- Inherits:
-
Object
- Object
- Kinopoisk::Movie
- Defined in:
- lib/kinopoisk/movie.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#title ⇒ Object
Returns a string containing title in russian.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
-
#actors ⇒ Object
Returns an array of strings containing actor names.
-
#art_directors ⇒ Object
Returns an array of strings containing art director names.
-
#box_office_ru ⇒ Object
Returns a string containing Russia box-office.
-
#box_office_us ⇒ Object
Returns a string containing USA box-office.
-
#box_office_world ⇒ Object
Returns a string containing world box-office.
-
#budget ⇒ Object
Returns a string containing budget for the movie.
-
#composers ⇒ Object
Returns an array of strings containing composer names.
-
#countries ⇒ Object
Returns an array of strings containing countries.
-
#description ⇒ Object
Returns a string containing movie description.
-
#directors ⇒ Object
Returns an array of strings containing director names.
-
#duration ⇒ Object
Returns a string containing duration of the film.
-
#editors ⇒ Object
Returns an array of strings containing editor names.
-
#genres ⇒ Object
Returns an array of strings containing genres.
-
#imdb_rating ⇒ Object
Returns a float imdb rating.
-
#imdb_rating_count ⇒ Object
Returns an integer imdb rating vote count.
-
#initialize(input, title = nil) ⇒ Movie
constructor
New instance can be initialized with id(integer) or title(string).
-
#length ⇒ Object
Returns an integer length of the movie in minutes.
-
#minimal_age ⇒ Object
Returns a string containing minimal age.
-
#operators ⇒ Object
Returns an array of strings containing operator names.
-
#poster ⇒ Object
Returns a url to a small sized poster.
-
#poster_big ⇒ Object
Returns a url to a big sized poster.
-
#premiere_ru ⇒ Object
Returns a string containing Russian premiere date.
-
#premiere_world ⇒ Object
Returns a string containing world premiere date.
-
#producers ⇒ Object
Returns an array of strings containing producer names.
-
#rating ⇒ Object
Returns a float kinopoisk rating.
-
#rating_count ⇒ Object
Returns an integer kinopoisk rating vote count.
-
#slogan ⇒ Object
Returns a string containing movie slogan.
-
#title_en ⇒ Object
Returns a string containing title in english.
-
#writers ⇒ Object
Returns an array of strings containing writer names.
-
#year ⇒ Object
Returns an integer release year.
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
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/kinopoisk/movie.rb', line 4 def id @id end |
#title ⇒ Object
Returns a string containing title in russian
29 30 31 |
# File 'lib/kinopoisk/movie.rb', line 29 def title @title end |
#url ⇒ Object
Returns the value of attribute url.
4 5 6 |
# File 'lib/kinopoisk/movie.rb', line 4 def url @url end |
Instance Method Details
#actors ⇒ Object
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_directors ⇒ Object
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_ru ⇒ Object
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_us ⇒ Object
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_world ⇒ Object
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 |
#budget ⇒ Object
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 |
#composers ⇒ Object
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 |
#countries ⇒ Object
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 |
#description ⇒ Object
Returns a string containing movie description
109 110 111 |
# File 'lib/kinopoisk/movie.rb', line 109 def description search_by_itemprop 'description' end |
#directors ⇒ Object
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 |
#duration ⇒ Object
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 |
#editors ⇒ Object
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 |
#genres ⇒ Object
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_rating ⇒ Object
Returns a float imdb rating
39 40 41 |
# File 'lib/kinopoisk/movie.rb', line 39 def doc.search('div.block_2 div:eq(2)').text[/\d.\d\d/].to_f end |
#imdb_rating_count ⇒ Object
Returns an integer imdb rating vote count
34 35 36 |
# File 'lib/kinopoisk/movie.rb', line 34 def doc.search('div.block_2 div:eq(2)').text.gsub(/.*\(/, '').gsub(/[ ()]/, '').to_i end |
#length ⇒ Object
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_age ⇒ Object
Returns a string containing minimal age
164 165 166 |
# File 'lib/kinopoisk/movie.rb', line 164 def minimal_age search_by_text('возраст').strip end |
#operators ⇒ Object
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 |
#poster ⇒ Object
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_big ⇒ Object
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_ru ⇒ Object
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_world ⇒ Object
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 |
#producers ⇒ Object
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 |
#rating ⇒ Object
Returns a float kinopoisk rating
89 90 91 |
# File 'lib/kinopoisk/movie.rb', line 89 def doc.search('span.rating_ball').text.to_f end |
#rating_count ⇒ Object
Returns an integer kinopoisk rating vote count
114 115 116 |
# File 'lib/kinopoisk/movie.rb', line 114 def search_by_itemprop('ratingCount').gsub(' ', '').to_i end |
#slogan ⇒ Object
Returns a string containing movie slogan
159 160 161 |
# File 'lib/kinopoisk/movie.rb', line 159 def slogan search_by_text 'слоган' end |
#title_en ⇒ Object
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 |
#writers ⇒ Object
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 |
#year ⇒ Object
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 |