Class: Kinopoisk::Movie
- Inherits:
-
Object
- Object
- Kinopoisk::Movie
- Defined in:
- lib/kinopoisk/movie.rb
Constant Summary collapse
- HEADERS =
{'Referer' => 'http://www.kinopoisk.ru/', 'User-Agent' => 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.8) Gecko/20100723 Ubuntu/10.04 (lucid) Firefox/3.6.8'}
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#title ⇒ Object
Returns the value of attribute title.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #author ⇒ Object
- #cast_members ⇒ Object
- #country ⇒ Object
- #description ⇒ Object (also: #plot)
- #director ⇒ Object
- #genres ⇒ Object
-
#initialize(movie_id, title = nil) ⇒ Movie
constructor
A new instance of Movie.
- #length ⇒ Object
- #poster ⇒ Object
- #producer ⇒ Object
- #rating ⇒ Object
- #thumbnail ⇒ Object
- #year ⇒ Object
Constructor Details
#initialize(movie_id, title = nil) ⇒ Movie
Returns a new instance of Movie.
8 9 10 11 12 |
# File 'lib/kinopoisk/movie.rb', line 8 def initialize(movie_id, title = nil) @id = movie_id @url = "http://www.kinopoisk.ru/level/1/film/#{movie_id}/" @title = title if title end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/kinopoisk/movie.rb', line 3 def id @id end |
#title ⇒ Object
Returns the value of attribute title.
3 4 5 |
# File 'lib/kinopoisk/movie.rb', line 3 def title @title end |
#url ⇒ Object
Returns the value of attribute url.
3 4 5 |
# File 'lib/kinopoisk/movie.rb', line 3 def url @url end |
Instance Method Details
#author ⇒ Object
14 15 16 17 18 |
# File 'lib/kinopoisk/movie.rb', line 14 def document.search("//td[text()='сценарий'] ~ a").map do |link| link.inner_html.strip end end |
#cast_members ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/kinopoisk/movie.rb', line 20 def cast_members skip = false document.search("//td[@class='actor_list']/span/a").map do |link| skip = true if link.inner_html.strip == '...' link.inner_html.strip unless skip end.compact end |
#country ⇒ Object
28 29 30 |
# File 'lib/kinopoisk/movie.rb', line 28 def country document.search("//table[@class='info']/tr/td/a[@href*=/m_act%5Bcountry%5D/]").inner_html rescue nil end |
#description ⇒ Object Also known as: plot
32 33 34 35 36 |
# File 'lib/kinopoisk/movie.rb', line 32 def description text = document.search("//td[@class='news']/span[@class='_reachbanner_']").inner_html text = text.gsub /<br[\s\/]*>/, "\n" Hpricot(text).inner_text#.strip.gsub ' ', ' ' end |
#director ⇒ Object
39 40 41 42 43 |
# File 'lib/kinopoisk/movie.rb', line 39 def director document.search("//td[text()='режиссер'] ~ a").map do |link| link.inner_html.strip end end |
#genres ⇒ Object
45 46 47 48 49 50 |
# File 'lib/kinopoisk/movie.rb', line 45 def genres result = document.search("//td[text()='жанр'] ~ a").map do |link| link.inner_html.strip end result.reject{ |g| g == '...'} end |
#length ⇒ Object
52 53 54 |
# File 'lib/kinopoisk/movie.rb', line 52 def length document.search("//td[@id='runtime']").inner_html.strip.to_i end |
#poster ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/kinopoisk/movie.rb', line 56 def poster begin cover_page.search("//table[@id='main_table']/tr/td/a/img").first.attributes['src'] rescue nil end end |
#producer ⇒ Object
64 65 66 67 68 |
# File 'lib/kinopoisk/movie.rb', line 64 def producer document.search("//td[text()='продюсер'] ~ a").map do |link| link.inner_html.strip end end |
#rating ⇒ Object
70 71 72 73 |
# File 'lib/kinopoisk/movie.rb', line 70 def result = document.search("//div[@class='block_2']/div/a[@class='continue']").inner_html result.gsub /<[\s\S]+$/, '' end |
#thumbnail ⇒ Object
75 76 77 78 79 80 |
# File 'lib/kinopoisk/movie.rb', line 75 def thumbnail images = document.search("//img[@src*=/images/']").map do |item| "http://www.kinopoisk.ru#{item.attributes['src']}" end images.reject{ |item| item !~ /images\/film\// }.first end |
#year ⇒ Object
82 83 84 |
# File 'lib/kinopoisk/movie.rb', line 82 def year document.search("//table[@class='info']/tr/td/a[@href*=/m_act%5Byear%5D/]").inner_html.to_i rescue nil end |