class ZombieBattleground::Api::Responses::GetDecksResponse
Response validator for GetDecks
Attributes
@!attribute [r] decks the deck found for the page and limit
@return [Array<ZombieBattleground::Api::Models::Deck>]
@example
response.decks #=> [ZombieBattleground::Api::Models::Deck]
@api public
@!attribute [r] decks_count
the number of decks returned in the response
@return [Integer]
@example
response.decks_count #=> 1
@api public
@!attribute [r] limit the limit of results for the page
@return [Integer]
@example
response.limit #=> 100
@api public
@!attribute [r] page the page number of the results
@return [Integer]
@example
response.page #=> 1
@api public
@!attribute [a] remove_invalid
flag to remove objects in response that are invalid during validation
@return [Boolean]
@example
response.remove_invalid = true
@api public
@!attribute [r] total the total number of results available
@return [Integer]
@example
response.total #=> 1505
@api public
Public Class Methods
Creates a new GetDecksResponse
@param response [Faraday::Response] Faraday response from endpoint
@return [ZombieBattleground::Api::GetDecksResponse]
@example
response = ZombieBattleground::Api::GetDecksResponse.new(faraday_response) # => ZombieBattleground::Api::GetDecksResponse
@api public
# File lib/zombie_battleground/api/responses/get_decks_response.rb, line 109 def initialize(response) handle_errors(response) JSON.parse(response.body).each do |key, value| if key == 'decks' # Keep the API response count, it will differ when invalid decks are stripped @decks_count = value.size instance_variable_set( "@#{key}".to_sym, value.map { |deck| ZombieBattleground::Api::Models::Deck.new(deck) } ) else instance_variable_set("@#{key}".to_sym, value) end end end
Private Instance Methods
Validator for decks in decks
@return [void]
@api private
# File lib/zombie_battleground/api/responses/get_decks_response.rb, line 153 def decks_contains_valid_decks @decks.each do |deck| next if deck.is_a?(ZombieBattleground::Api::Models::Deck) && deck.valid? && deck.errors.size.zero? errors.add(:decks, 'decks must be an array of Deck') end end
Validator for decks attribute
@return [void]
@api private
# File lib/zombie_battleground/api/responses/get_decks_response.rb, line 134 def decks_is_an_array_of_deck unless @decks.is_a?(Array) errors.add(:decks, 'Decks must be an array') return end if remove_invalid remove_invalid_decks else decks_contains_valid_decks end end
Removes invalid vards from deck
@return [void]
@api private
# File lib/zombie_battleground/api/responses/get_decks_response.rb, line 169 def remove_invalid_decks @decks.select! do |deck| deck.is_a?(ZombieBattleground::Api::Models::Deck) && deck.valid? && deck.errors.size.zero? end end