lib/tvdb2/series.rb in tvdb2-0.1.1 vs lib/tvdb2/series.rb in tvdb2-0.1.2

- old
+ new

@@ -72,10 +72,11 @@ # @return [TvdbStruct] return the summary of the series. # @raise [RequestError] def series_summary @client.series_summary(self.id) end + alias_method :summary, :series_summary # Retrieve the episodes of the series. # # @param params (see API#episodes) # @option params (see API#episodes) @@ -203,9 +204,27 @@ ps.shuffle! if random ps.first ? ps.first.url : nil end # @!endgroup + + # @param [Boolean] episodes if true include all episodes + # ({Episode#to_h}) on the hash. + # @param [Boolean] retrieve_all_fields if true retrieve all fields + # (from api) of the series. + # @return [Hash] the series to hash. + def to_h(episodes: false, retrieve_all_fields: false) + get_all_fields! if retrieve_all_fields + hash = {} + FIELDS.each do |field| + hash[field.to_sym] = instance_variable_get("@#{field}") + end + hash[:name] = @seriesName + hash[:poster_url] = self.poster_url + hash[:banner_url] = self.banner_url + hash[:episodes] = self.episodes.map(&:to_h) if episodes + return hash + end private # Get all data fields for this series. Calling api endpoint `GET # /series/{id}`.