Class: AtTheMovies::Parsers::Review

Inherits:
AtTheMovies::Parser show all
Defined in:
lib/at_the_movies/parsers/review.rb

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

Attributes inherited from AtTheMovies::Parser

#page

Instance Method Summary collapse

Methods inherited from AtTheMovies::Parser

#initialize, parse

Constructor Details

This class inherits a constructor from AtTheMovies::Parser

Instance Method Details

#classificationObject



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

#dateObject



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

#detailsObject



23
24
25
# File 'lib/at_the_movies/parsers/review.rb', line 23

def details
  @details ||= @page.search('p.moviedetails').inner_html.strip
end

#durationObject



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

#genreObject



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

#parseObject



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

#ratingsObject



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

#titleObject



27
28
29
# File 'lib/at_the_movies/parsers/review.rb', line 27

def title
  @page.title.strip[15..-1]
end