Class: ImdbParty::Movie

Inherits:
Object
  • Object
show all
Defined in:
lib/imdb_party/movie.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Movie

Returns a new instance of Movie


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/imdb_party/movie.rb', line 5

def initialize(options={})      
  if not options.nil? and options.keys.first.class == Symbol
    options.keys.each { |name| instance_variable_set "@" + name.to_s, options[name] }; return
  end
  
  @imdb_id = options["tconst"]
  @title = options["title"]
  @tagline = options["tagline"]
  @plot = options["plot"]["outline"] if options["plot"]
  @runtime = "#{(options["runtime"]["time"]/60).to_i} min" if options["runtime"]
  @rating = options["rating"]
  @poster_url = options["image"]["url"] if options["image"]
  @release_date = options["release_date"]["normal"] if options["release_date"] && options["release_date"]["normal"]
  @certification = options["certificate"]["certificate"] if options["certificate"] && options["certificate"]["certificate"]
  @genres = options["genres"] || []
  
  # Sometimes the @release_date object is a string instead of a date object
  if @release_date.class == String
    [{:regex => /^\d{4}-\d{2}$/, :concat => "-01"}, {:regex => /^\d{4}$/, :concat => "-01-01"}].each do |value|
      if @release_date.match(value[:regex])
        @release_date = Date.parse(@release_date << value[:concat]); break
      end
    end
  end
    
  # parse directors
  @directors = options["directors_summary"] ? options["directors_summary"].map { |d| Person.new(d) } : []

  # parse directors
  @writers = []
  @writers = options["writers_summary"] ? options["writers_summary"].map { |w| Person.new(w) } : []

  # parse actors
  @actors = []
  @actors = options["cast_summary"] ? options["cast_summary"].map { |a| Person.new(a) } : []

  #parse trailers
  @trailers = {}
  if options["trailer"] && options["trailer"]["encodings"]
    options["trailer"]["encodings"].each_pair do |k,v|
      @trailers[v["format"]] = v["url"]
    end
  end

end

Instance Attribute Details

#actorsObject

Returns the value of attribute actors


3
4
5
# File 'lib/imdb_party/movie.rb', line 3

def actors
  @actors
end

#certificationObject

Returns the value of attribute certification


3
4
5
# File 'lib/imdb_party/movie.rb', line 3

def certification
  @certification
end

#companyObject

Returns the value of attribute company


3
4
5
# File 'lib/imdb_party/movie.rb', line 3

def company
  @company
end

#directorsObject

Returns the value of attribute directors


3
4
5
# File 'lib/imdb_party/movie.rb', line 3

def directors
  @directors
end

#genresObject

Returns the value of attribute genres


3
4
5
# File 'lib/imdb_party/movie.rb', line 3

def genres
  @genres
end

#imdb_idObject

Returns the value of attribute imdb_id


3
4
5
# File 'lib/imdb_party/movie.rb', line 3

def imdb_id
  @imdb_id
end

#plotObject

Returns the value of attribute plot


3
4
5
# File 'lib/imdb_party/movie.rb', line 3

def plot
  @plot
end

#poster_urlObject

Returns the value of attribute poster_url


3
4
5
# File 'lib/imdb_party/movie.rb', line 3

def poster_url
  @poster_url
end

#ratingObject

Returns the value of attribute rating


3
4
5
# File 'lib/imdb_party/movie.rb', line 3

def rating
  @rating
end

#release_dateObject

Returns the value of attribute release_date


3
4
5
# File 'lib/imdb_party/movie.rb', line 3

def release_date
  @release_date
end

#runtimeObject

Returns the value of attribute runtime


3
4
5
# File 'lib/imdb_party/movie.rb', line 3

def runtime
  @runtime
end

#taglineObject

Returns the value of attribute tagline


3
4
5
# File 'lib/imdb_party/movie.rb', line 3

def tagline
  @tagline
end

#titleObject

Returns the value of attribute title


3
4
5
# File 'lib/imdb_party/movie.rb', line 3

def title
  @title
end

#trailersObject

Returns the value of attribute trailers


3
4
5
# File 'lib/imdb_party/movie.rb', line 3

def trailers
  @trailers
end

#writersObject

Returns the value of attribute writers


3
4
5
# File 'lib/imdb_party/movie.rb', line 3

def writers
  @writers
end

#yearObject

Returns the value of attribute year


3
4
5
# File 'lib/imdb_party/movie.rb', line 3

def year
  @year
end