Sha256: 8f7ff9c8c6737efb8beb553dceac3e0da9c1159886b7b68c67f44e05708b76ca
Contents?: true
Size: 1.51 KB
Versions: 4
Compression:
Stored size: 1.51 KB
Contents
require 'ostruct' module Tvdb2 # OpenStruct that define `_url` methods to get url from images relative paths # returned from api. # # @example # got = client.best_search('Game of Thrones') # puts got.posters.first.fileName # print relative path posters/121361-1.jpg # puts got.posters.first.fileName_url # print url https://thetvdb.com/banners/posters/121361-1.jpg class TvdbStruct < OpenStruct # @param [Client] tvdb a TVDB api client. Only to compatibily with {Client} # and {Episode} constructor. # @param [Hash] hash the optional hash, if given, will generate attributes # and values (can be a Hash, an OpenStruct or a Struct). # # @note You should never need to create this object manually. def initialize(tvdb = nil, hash = {}) super(hash) end # @!parse # # @return [String] the url string of relative image path stored in # # `image` field. `nil` if `image` field is `nil`. # def image_url; end # # @return [String] the url string of relative image path stored in # # `fileName` field. `nil` if `fileName` field is `nil`. # def fileName_url; end # # @return [String] the url string of relative image path stored in # # `thumbnail` field. `nil` if `thumbnail` field is `nil`. # def thumbnail_url; end %w(image fileName thumbnail).each do |field| define_method "#{field}_url" do self.send(field) ? Client.image_url(self.send(field)) : nil end end alias_method :url, :fileName_url end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
tvdb2-0.1.3 | lib/tvdb2/tvdb_struct.rb |
tvdb2-0.1.2 | lib/tvdb2/tvdb_struct.rb |
tvdb2-0.1.1 | lib/tvdb2/tvdb_struct.rb |
tvdb2-0.1.0 | lib/tvdb2/tvdb_struct.rb |