Class: Allocine::AllocineBase

Inherits:
Object
  • Object
show all
Defined in:
lib/allocine/allocine_base.rb

Overview

Represents a AllocineBase

Direct Known Subclasses

Movie, Serie

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(allocine_id, title = nil) ⇒ AllocineBase

Returns a new instance of AllocineBase.



11
12
13
14
# File 'lib/allocine/allocine_base.rb', line 11

def initialize(allocine_id, title = nil)
  @id = allocine_id
  @url = "http://api.allocine.fr/rest/v3/movie?code=#{allocine_id}&profile=large&format=json&partner=YW5kcm9pZC12M3M"
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



9
10
11
# File 'lib/allocine/allocine_base.rb', line 9

def id
  @id
end

#title(force_refresh = false) ⇒ Object

Returns a string containing the title



67
68
69
# File 'lib/allocine/allocine_base.rb', line 67

def title
  @title
end

#urlObject

Returns the value of attribute url.



9
10
11
# File 'lib/allocine/allocine_base.rb', line 9

def url
  @url
end

Instance Method Details

#actorsObject

Returns an array with cast members



22
23
24
# File 'lib/allocine/allocine_base.rb', line 22

def actors
  document["castingShort"]["actors"].split(", ") rescue nil
end

#countriesObject

Returns an array of countries as strings.



32
33
34
# File 'lib/allocine/allocine_base.rb', line 32

def countries
  document["nationality"].collect {|nation| nation["$"]} rescue nil
end

#directorsObject

Returns the name of the director



17
18
19
# File 'lib/allocine/allocine_base.rb', line 17

def directors
  document["castingShort"]["directors"].split(", ") rescue nil
end

#genresObject

Returns an array of genres (as strings)



27
28
29
# File 'lib/allocine/allocine_base.rb', line 27

def genres
  document["genre"].collect {|gender| gender["$"]} rescue nil
end

#lengthObject

Returns the duration of the movie in minutes as an integer.



37
38
39
# File 'lib/allocine/allocine_base.rb', line 37

def length
  document["runtime"].to_i/60 rescue nil 
end

#original_titleObject

Returns originalTitle.



76
77
78
# File 'lib/allocine/allocine_base.rb', line 76

def original_title
  document["originalTitle"] rescue nil
end

#plot(short = true) ⇒ Object



91
92
93
# File 'lib/allocine/allocine_base.rb', line 91

def plot(short = true)
  short ? document["synopsisShort"] : document["synopsis"]
end

#posterObject

Returns a string containing the URL to the movie poster.



42
43
44
# File 'lib/allocine/allocine_base.rb', line 42

def poster
  document["poster"]["href"] rescue nil 
end

#press_ratingObject

Returns a float containing the average user rating



57
58
59
# File 'lib/allocine/allocine_base.rb', line 57

def press_rating
  document["statistics"]["pressRating"] rescue nil 
end

#production_yearObject

Return production Year for the movie



87
88
89
# File 'lib/allocine/allocine_base.rb', line 87

def production_year
  document["productionYear"]
end

#release_dateObject

Returns release date for the movie.



82
83
84
# File 'lib/allocine/allocine_base.rb', line 82

def release_date
  document["release"]["releaseDate"] rescue nil
end

#trailerObject

Returns a string containing the URL to the movie trailer.



52
53
54
# File 'lib/allocine/allocine_base.rb', line 52

def trailer
  document["trailer"]["href"] rescue nil 
end

#trailer_idObject

Returns a string containing trailer code.



47
48
49
# File 'lib/allocine/allocine_base.rb', line 47

def trailer_id
  document["trailer"]["code"] rescue nil 
end

#user_ratingObject

Returns an int containing the number of user ratings



62
63
64
# File 'lib/allocine/allocine_base.rb', line 62

def user_rating
  document["statistics"]["userRating"] rescue nil 
end