Class: AtTheMovies::Parsers::Review
Constant Summary
collapse
- RATINGS =
{
"zero" => 0,
"half" => 0.5,
"one" => 1,
"one-and-a-half" => 1.5,
"two" => 2,
"two-and-a-half" => 2.5,
"three" => 3,
"three-and-a-half" => 3.5,
"four" => 4,
"four-and-a-half" => 4.5,
"five" => 5
}
Instance Attribute Summary
#page
Instance Method Summary
collapse
#initialize, parse
Instance Method Details
#classification ⇒ Object
31
32
33
|
# File 'lib/at_the_movies/parsers/review.rb', line 31
def classification
details.scan(/Classification:<\/strong> ([[:alnum:][:punct:][:space:]]{1,10})<br>/).flatten.first
end
|
#date ⇒ Object
35
36
37
|
# File 'lib/at_the_movies/parsers/review.rb', line 35
def date
Date.parse(@page.search('meta[@name="Date"]').first['content'].gsub('/', '-'))
end
|
#details ⇒ Object
23
24
25
|
# File 'lib/at_the_movies/parsers/review.rb', line 23
def details
@details ||= @page.search('p.moviedetails').inner_html.strip
end
|
#duration ⇒ Object
39
40
41
|
# File 'lib/at_the_movies/parsers/review.rb', line 39
def duration
details.scan(/Duration:<\/strong> ([0-9]{1,3})/).flatten.first.to_i
end
|
#genre ⇒ Object
43
44
45
|
# File 'lib/at_the_movies/parsers/review.rb', line 43
def genre
details.scan(/Genre:<\/strong> ([[:alnum:][:space:][:punct:]]+)<br><strong>Director:/).flatten.first
end
|
#parse ⇒ Object
18
19
20
21
|
# File 'lib/at_the_movies/parsers/review.rb', line 18
def parse
return unless @page.body[/Review by/]
AtTheMovies::Review.new(title, classification, date, duration, genre, ratings, @page.uri.to_s)
end
|
#ratings ⇒ Object
47
48
49
50
51
52
53
54
55
|
# File 'lib/at_the_movies/parsers/review.rb', line 47
def ratings
score = @page.search('p.score')
ratings = score.css('img').collect { |image| image['alt'][0..-7] }
ratings = score.css('p.score').text.scan(/Margaret|David/).inject_with_index({}) do |hash, person, index|
hash[person] = RATINGS[ratings[index]]
hash
end
ratings
end
|
#title ⇒ Object
27
28
29
|
# File 'lib/at_the_movies/parsers/review.rb', line 27
def title
@page.title.strip[15..-1]
end
|