Class: Allocine::AllocineBase

Inherits:
Object
  • Object
show all
Defined in:
lib/allocine_parser/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


12
13
14
15
# File 'lib/allocine_parser/allocine_base.rb', line 12

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


10
11
12
# File 'lib/allocine_parser/allocine_base.rb', line 10

def id
  @id
end

#title(force_refresh = false) ⇒ Object

Returns a string containing the title


104
105
106
# File 'lib/allocine_parser/allocine_base.rb', line 104

def title
  @title
end

#urlObject

Returns the value of attribute url


10
11
12
# File 'lib/allocine_parser/allocine_base.rb', line 10

def url
  @url
end

Instance Method Details

#actorsObject

Returns actors


55
56
57
58
59
60
61
# File 'lib/allocine_parser/allocine_base.rb', line 55

def actors
  actors = []
  actors_ids.each do |id|
    actors << Allocine::Person.new(id)
  end
  actors
end

#actors_idsObject

Returns ids of actors (major)


46
47
48
49
50
51
52
# File 'lib/allocine_parser/allocine_base.rb', line 46

def actors_ids
  actors_ids = []
  actors_name.each_with_index do |actor, index|
    actors_ids << document["castMember"][directors_name.size + index]["person"]["code"] if actor == document["castMember"][directors_name.size + index]["person"]["name"]
  end
  actors_ids
end

#actors_nameObject

Returns an array with cast members


41
42
43
# File 'lib/allocine_parser/allocine_base.rb', line 41

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

#countriesObject

Returns an array of countries as strings.


69
70
71
# File 'lib/allocine_parser/allocine_base.rb', line 69

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

#directorsObject

Returns directors


23
24
25
26
27
28
29
# File 'lib/allocine_parser/allocine_base.rb', line 23

def directors
  directors = []
  directors_ids.each do |id|
    directors << Allocine::Person.new(id)
  end
  directors
end

#directors_idsObject

Returns ids of directors


32
33
34
35
36
37
38
# File 'lib/allocine_parser/allocine_base.rb', line 32

def directors_ids
  directors_ids = []
  directors_name.each_with_index do |director, index|
    directors_ids << document["castMember"][index]["person"]["code"] if director == document["castMember"][index]["person"]["name"]
  end
  directors_ids
end

#directors_nameObject

Returns the name of the director


18
19
20
# File 'lib/allocine_parser/allocine_base.rb', line 18

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

#genresObject

Returns an array of genres (as strings)


64
65
66
# File 'lib/allocine_parser/allocine_base.rb', line 64

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

#lengthObject

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


74
75
76
# File 'lib/allocine_parser/allocine_base.rb', line 74

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

#original_titleObject

Returns originalTitle.


113
114
115
# File 'lib/allocine_parser/allocine_base.rb', line 113

def original_title
  document["originalTitle"] rescue nil
end

#plot(short = true) ⇒ Object


127
128
129
# File 'lib/allocine_parser/allocine_base.rb', line 127

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

#posterObject

Returns a string containing the URL to the movie poster.


79
80
81
# File 'lib/allocine_parser/allocine_base.rb', line 79

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

#press_ratingObject

Returns a float containing the average user rating


94
95
96
# File 'lib/allocine_parser/allocine_base.rb', line 94

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

#production_yearObject

Return production Year for the movie


123
124
125
# File 'lib/allocine_parser/allocine_base.rb', line 123

def production_year
  document["productionYear"]
end

#release_dateObject

Returns release date for the movie.


118
119
120
# File 'lib/allocine_parser/allocine_base.rb', line 118

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

#trailerObject

Returns a string containing the URL to the movie trailer.


89
90
91
# File 'lib/allocine_parser/allocine_base.rb', line 89

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

#trailer_idObject

Returns a string containing trailer code.


84
85
86
# File 'lib/allocine_parser/allocine_base.rb', line 84

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

#user_ratingObject

Returns an int containing the number of user ratings


99
100
101
# File 'lib/allocine_parser/allocine_base.rb', line 99

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