Sha256: 1ffd8d8d43a121b86c5420c8955735502369dca41759c14e4d32b798dd732311

Contents?: true

Size: 1.19 KB

Versions: 11

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true
require_relative 'omdb_api'

module Movlog
  # Movie info
  class Movie
    attr_reader :imdb_id, :type, :title, :year, :released, :poster
    attr_reader :rating, :plot, :runtime, :genre
    attr_reader :awards, :director, :actors
    attr_reader :country, :language
    attr_reader :response
    attr_reader :location

    def initialize(data:)
      @imdb_id = data[:imdb_id]
      @title = data[:title]
      @year = data[:year]
      @type = data[:type]
      @poster = data[:poster]
    end

    def self.find(data)
      new(data: data)
    end

    def get_location
      return @location if @location
      @location = OmdbApi.location(@imdb_id)
    end

    def get_details
      movie_details = OmdbApi.movie_info(@title)
      parse_details(details: movie_details)
    end

    def parse_details(details:)
      @rating = details['imdbRating']
      @plot = details['Plot']
      @runtime = details['Runtime']
      @awards = details['Awards']
      @director = details['Director']
      @actors = details['Actors']
      @country = details['Country']
      @language = details['Language']
      @released = details['Released']
      @genre = details['Genre']
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
movlog-0.4.2 lib/movlog/movie.rb
movlog-0.4.1 lib/movlog/movie.rb
movlog-0.4.0 lib/movlog/movie.rb
movlog-0.3.15 lib/movlog/movie.rb
movlog-0.3.14 lib/movlog/movie.rb
movlog-0.3.13 lib/movlog/movie.rb
movlog-0.3.12 lib/movlog/movie.rb
movlog-0.3.11 lib/movlog/movie.rb
movlog-0.3.10 lib/movlog/movie.rb
movlog-0.3.9 lib/movlog/movie.rb
movlog-0.3.8 lib/movlog/movie.rb