Class: Container::Movie
- Inherits:
-
Object
- Object
- Container::Movie
- Defined in:
- lib/imdb_vote_history/container.rb
Instance Method Summary collapse
-
#imdb_id ⇒ Object
Returns the imdb id for the movie.
-
#imdb_link ⇒ Object
Returns the full imdb url for the movie.
-
#initialize(args) ⇒ Movie
constructor
A new instance of Movie.
- #method_missing(method, *args) ⇒ Object
-
#valid? ⇒ Boolean
Does the container contains a valid imdb url? Return true if the url is valid.
Constructor Details
#initialize(args) ⇒ Movie
Returns a new instance of Movie.
5 6 7 |
# File 'lib/imdb_vote_history/container.rb', line 5 def initialize(args) args.keys.each { |name| instance_variable_set "@" + name.to_s, args[name] } end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
31 32 33 34 |
# File 'lib/imdb_vote_history/container.rb', line 31 def method_missing(method, *args) return movie.send(method, *args) if exists? and movie.methods.include?(prepare(method)) raise exists? ? NoMethodError.new("Undefined method `#{method}' for #{movie.class}") : ArgumentError.new("The imdb #{imdb_id} is invalid") end |
Instance Method Details
#imdb_id ⇒ Object
Returns the imdb id for the movie. Example:
> tt0066026
12 13 14 |
# File 'lib/imdb_vote_history/container.rb', line 12 def imdb_id imdb_link.match(/(tt\d+)/).to_a[1] end |
#imdb_link ⇒ Object
Returns the full imdb url for the movie. Example:
> www.imdb.com/title/tt0066026/
19 20 21 |
# File 'lib/imdb_vote_history/container.rb', line 19 def imdb_link "http://www.imdb.com#{@imdb_link}" end |
#valid? ⇒ Boolean
Does the container contains a valid imdb url? Return true if the url is valid. Example on valid url:
> www.imdb.com/title/tt0066026/
27 28 29 |
# File 'lib/imdb_vote_history/container.rb', line 27 def valid? !! imdb_link.match(/http:\/\/www\.imdb\.com\/title\/tt\d{2,}/i) end |