Class: Myimdb::Scraper::Imdb
- Inherits:
-
Base
- Object
- Base
- Myimdb::Scraper::Imdb
show all
- Defined in:
- lib/myimdb/scraper/imdb.rb
Constant Summary
HandleExceptions::EXCEPTIONS_ENABLED
Instance Method Summary
collapse
Methods inherited from Base
all, #name, #summary, #to_hash
#scraper_unescape_html, #strip_useless_chars
included
Constructor Details
#initialize(url) ⇒ Imdb
Returns a new instance of Imdb.
4
5
6
|
# File 'lib/myimdb/scraper/imdb.rb', line 4
def initialize(url)
@url = url
end
|
Instance Method Details
#directors ⇒ Object
8
9
10
|
# File 'lib/myimdb/scraper/imdb.rb', line 8
def directors
document.css('#overview-top .txt-block h4:contains("Director") ~ a:not(:contains(" more "))').collect{ |a| a.text }
end
|
#directors_with_url ⇒ Object
12
13
14
|
# File 'lib/myimdb/scraper/imdb.rb', line 12
def directors_with_url
document.css('#overview-top .txt-block h4:contains("Director") ~ a:not(:contains(" more "))').collect{ |a| {:name=> a.text, :url=> "http://www.imdb.com#{a['href']}" } }
end
|
#genres ⇒ Object
32
33
34
|
# File 'lib/myimdb/scraper/imdb.rb', line 32
def genres
document.css('.see-more.inline.canwrap h4:contains("Genres:") ~ a:not(:contains(" more "))').collect{ |a| a.text }
end
|
#image ⇒ Object
52
53
54
|
# File 'lib/myimdb/scraper/imdb.rb', line 52
def image
document.css('#img_primary img').first['src']
end
|
#plot ⇒ Object
40
41
42
|
# File 'lib/myimdb/scraper/imdb.rb', line 40
def plot
strip_useless_chars(document.css('.article h2:contains("Storyline") ~ p').inner_text).gsub(/Written by.*/, '')
end
|
#rating ⇒ Object
24
25
26
|
# File 'lib/myimdb/scraper/imdb.rb', line 24
def rating
document.css(".star-box-details span[itemprop='ratingValue']").inner_text.strip.to_f
end
|
#release_date ⇒ Object
48
49
50
|
# File 'lib/myimdb/scraper/imdb.rb', line 48
def release_date
Date.parse(document.css("a[title='See all release dates']").inner_text)
end
|
#tagline ⇒ Object
36
37
38
|
# File 'lib/myimdb/scraper/imdb.rb', line 36
def tagline
strip_useless_chars(document.css('.txt-block h4:contains("Taglines:")').first.parent.inner_text).gsub(/Taglines |See more/, '') rescue nil
end
|
#votes ⇒ Object
28
29
30
|
# File 'lib/myimdb/scraper/imdb.rb', line 28
def votes
document.css(".star-box a[href='ratings']").inner_text.strip.split(' ').first.sub(',', '').to_i
end
|
#writers ⇒ Object
16
17
18
|
# File 'lib/myimdb/scraper/imdb.rb', line 16
def writers
document.css('#overview-top .txt-block h4:contains("Writer") ~ a:not(:contains(" more "))').collect{ |a| a.text }
end
|
#writers_with_url ⇒ Object
20
21
22
|
# File 'lib/myimdb/scraper/imdb.rb', line 20
def writers_with_url
document.css('#overview-top .txt-block h4:contains("Writer") ~ a:not(:contains(" more "))').collect{ |a| {:name=> a.text, :url=> "http://www.imdb.com#{a['href']}" } }
end
|
#year ⇒ Object
44
45
46
|
# File 'lib/myimdb/scraper/imdb.rb', line 44
def year
release_date.year
end
|