Class: FilmBuff::Title

Inherits:
Object
  • Object
show all
Defined in:
lib/filmbuff/title.rb

Overview

Represents a single title from IMDb and contains all available data on it

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(imdb_hash) ⇒ Title

Create a new Title instance from an IMDb hash

Parameters:

  • imdb_hash (Hash)

    The hash with IMDb information to create a Title instance from



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/filmbuff/title.rb', line 42

def initialize(imdb_hash)
  @imdb_id = imdb_hash['tconst']
  @title = imdb_hash['title']
  @tagline = imdb_hash['tagline'] if imdb_hash['tagline']
  @plot = imdb_hash['plot']['outline'] if imdb_hash['plot']
  @runtime = imdb_hash['runtime']['time'] if imdb_hash['runtime']
  @rating = imdb_hash['rating']
  @votes = imdb_hash['num_votes']
  @poster_url = imdb_hash['image']['url'] if imdb_hash['image']
  @genres = imdb_hash['genres'] || []

  if imdb_hash['release_date']
    begin
      @release_date = Date.strptime(imdb_hash['release_date']['normal'],
                                    '%Y-%m-%d')
    rescue
      @release_date = imdb_hash['release_date']['normal']
    end
  end
end

Instance Attribute Details

#genresArray<String> (readonly)

Returns The genres of Title.

Returns:

  • (Array<String>)

    The genres of Title



32
33
34
# File 'lib/filmbuff/title.rb', line 32

def genres
  @genres
end

#imdb_idString (readonly)

Returns The IMDb ID of Title.

Returns:

  • (String)

    The IMDb ID of Title



7
8
9
# File 'lib/filmbuff/title.rb', line 7

def imdb_id
  @imdb_id
end

#plotString (readonly)

Returns The plot summary of Title.

Returns:

  • (String)

    The plot summary of Title



16
17
18
# File 'lib/filmbuff/title.rb', line 16

def plot
  @plot
end

#poster_urlString (readonly)

Returns The URL for the poster of Title.

Returns:

  • (String)

    The URL for the poster of Title



29
30
31
# File 'lib/filmbuff/title.rb', line 29

def poster_url
  @poster_url
end

#ratingFloat (readonly)

Returns The IMDb rating of Title.

Returns:

  • (Float)

    The IMDb rating of Title



22
23
24
# File 'lib/filmbuff/title.rb', line 22

def rating
  @rating
end

#release_dateDate, String (readonly)

Returns The release date of Title. Returns a Date when possible, otherwise a String.

Returns:

  • (Date, String)

    The release date of Title. Returns a Date when possible, otherwise a String



36
37
38
# File 'lib/filmbuff/title.rb', line 36

def release_date
  @release_date
end

#runtimeInteger (readonly)

Returns The runtime of Title in seconds.

Returns:

  • (Integer)

    The runtime of Title in seconds



19
20
21
# File 'lib/filmbuff/title.rb', line 19

def runtime
  @runtime
end

#taglineString (readonly)

Returns The tagline of Title.

Returns:

  • (String)

    The tagline of Title



13
14
15
# File 'lib/filmbuff/title.rb', line 13

def tagline
  @tagline
end

#titleString (readonly)

Returns The title of Title.

Returns:

  • (String)

    The title of Title



10
11
12
# File 'lib/filmbuff/title.rb', line 10

def title
  @title
end

#votesInteger (readonly)

Returns The amount of votes that have been used to determine the rating of Title.

Returns:

  • (Integer)

    The amount of votes that have been used to determine the rating of Title



26
27
28
# File 'lib/filmbuff/title.rb', line 26

def votes
  @votes
end