Class: ImdbVoteHistory
- Inherits:
-
Object
- Object
- ImdbVoteHistory
- Defined in:
- lib/imdb_vote_history.rb
Instance Attribute Summary collapse
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
-
.find_by_id(id) ⇒ Object
Fetches movies for the given ID.
-
.find_by_url(url) ⇒ Object
Fetches movies for the given URL.
Instance Method Summary collapse
-
#all ⇒ Object
Should we fetch all movies, even though pagination exists?.
-
#id ⇒ Object
A unique id for this particular list.
-
#initialize(id) ⇒ ImdbVoteHistory
constructor
Ingoing argument is the id to fetch movies from.
-
#movies ⇒ Object
Returns a list of movies of the Container::Movie type.
-
#user ⇒ Object
The owners username, nil if the page doesn’t exists.
Constructor Details
#initialize(id) ⇒ ImdbVoteHistory
Ingoing argument is the id to fetch movies from.
9 10 11 12 |
# File 'lib/imdb_vote_history.rb', line 9 def initialize(id) @movies = [] @url = "http://www.imdb.com/mymovies/list?l=#{id}" end |
Instance Attribute Details
#url ⇒ Object (readonly)
Returns the value of attribute url.
6 7 8 |
# File 'lib/imdb_vote_history.rb', line 6 def url @url end |
Class Method Details
.find_by_id(id) ⇒ Object
Fetches movies for the given ID. Returns an ImdbVoteHistory object.
26 27 28 29 |
# File 'lib/imdb_vote_history.rb', line 26 def self.find_by_id(id) raise ArgumentError.new("The id #{id} is invalid") unless id.to_s.match(/^\d{2,}$/) ImdbVoteHistory.new(id) end |
.find_by_url(url) ⇒ Object
Fetches movies for the given URL. Returns an ImdbVoteHistory object. The URL must be valid, otherwise an argument error will be raised. Example of valid URL:
> www.imdb.com/mymovies/list?l=32558051
19 20 21 22 |
# File 'lib/imdb_vote_history.rb', line 19 def self.find_by_url(url) raise ArgumentError.new("The url #{url} is invalid") unless url.to_s.match(/^(http:\/\/)?(w{3}\.)?imdb\.com\/mymovies\/list\?l=\d{2,}$/) ImdbVoteHistory.new(url.match(/list\?l=(\d+)/).to_a[1]) end |
Instance Method Details
#all ⇒ Object
Should we fetch all movies, even though pagination exists?
47 48 49 |
# File 'lib/imdb_vote_history.rb', line 47 def all @all = self end |
#id ⇒ Object
A unique id for this particular list. Return type is Fixnum.
42 43 44 |
# File 'lib/imdb_vote_history.rb', line 42 def id @url.match(/list\?l=(\d+)/).to_a[1].to_i end |
#movies ⇒ Object
Returns a list of movies of the Container::Movie type.
52 53 54 |
# File 'lib/imdb_vote_history.rb', line 52 def movies prepare! unless @movies.any?; @movies end |
#user ⇒ Object
The owners username, nil if the page doesn’t exists.
32 33 34 35 36 37 38 |
# File 'lib/imdb_vote_history.rb', line 32 def user begin content.at_css(".blurb a:nth-child(1)").content rescue NoMethodError nil # The default value if no user i found end end |