Class: AtTheMovies::Review

Inherits:
Object
  • Object
show all
Defined in:
lib/at_the_movies/review.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, classification, date, duration, genre, ratings, url) ⇒ Review

Returns a new instance of Review.



14
15
16
17
18
19
20
21
22
# File 'lib/at_the_movies/review.rb', line 14

def initialize(title, classification, date, duration, genre, ratings, url)
  @title = title
  @classification = classification
  @duration = duration
  @genre = genre
  @date = date
  @ratings = ratings
  @url = url
end

Instance Attribute Details

#classificationObject (readonly)

Returns the value of attribute classification.



3
4
5
# File 'lib/at_the_movies/review.rb', line 3

def classification
  @classification
end

#dateObject (readonly)

Returns the value of attribute date.



3
4
5
# File 'lib/at_the_movies/review.rb', line 3

def date
  @date
end

#durationObject (readonly)

Returns the value of attribute duration.



3
4
5
# File 'lib/at_the_movies/review.rb', line 3

def duration
  @duration
end

#genreObject (readonly)

Returns the value of attribute genre.



3
4
5
# File 'lib/at_the_movies/review.rb', line 3

def genre
  @genre
end

#ratingsObject (readonly)

Returns the value of attribute ratings.



3
4
5
# File 'lib/at_the_movies/review.rb', line 3

def ratings
  @ratings
end

#titleObject (readonly)

Returns the value of attribute title.



3
4
5
# File 'lib/at_the_movies/review.rb', line 3

def title
  @title
end

#urlObject (readonly)

Returns the value of attribute url.



3
4
5
# File 'lib/at_the_movies/review.rb', line 3

def url
  @url
end

Class Method Details

.latestObject



5
6
7
8
9
10
11
12
# File 'lib/at_the_movies/review.rb', line 5

def self.latest
  page = WWW::Mechanize.new.get('http://www.abc.net.au/atthemovies/review/')
  page.search('table.sideRating').first.css('a').inject([]) do |array, a|
    page = AtTheMovies::Parsers.for(a['href'], :only => "review")
    array << page
    array
  end.compact
end

Instance Method Details

#rating(rater = nil) ⇒ Object



24
25
26
27
# File 'lib/at_the_movies/review.rb', line 24

def rating(rater = nil)
  return total_rating unless rater
  @ratings[rater.to_s.capitalize]
end

#total_ratingObject



29
30
31
# File 'lib/at_the_movies/review.rb', line 29

def total_rating
  @ratings.inject(0) { |i,p| i += p[1]; i }
end