Class: Kinopoisk::Movie

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#titleObject

Returns the value of attribute title.



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

def title
  @title
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

Instance Method Details

#authorObject



14
15
16
17
18
# File 'lib/kinopoisk/movie.rb', line 14

def author
  document.search("//td[text()='сценарий'] ~ a").map do |link|
    link.inner_html.strip
  end
end

#cast_membersObject



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

#countryObject



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

#descriptionObject 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 '&nbsp;', ' '
end

#directorObject



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

#genresObject



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

#lengthObject



52
53
54
# File 'lib/kinopoisk/movie.rb', line 52

def length
  document.search("//td[@id='runtime']").inner_html.strip.to_i
end

#posterObject



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

#producerObject



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

#ratingObject



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

def rating
  result = document.search("//div[@class='block_2']/div/a[@class='continue']").inner_html
  result.gsub /<[\s\S]+$/, ''
end

#thumbnailObject



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

#yearObject



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