Class: Container::Movie

Inherits:
Object
  • Object
show all
Defined in:
lib/imdb_vote_history/container.rb

Instance Method Summary collapse

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_idObject

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

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/

Returns:

  • (Boolean)


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