class ZombieBattleground::Api::Models::Deck
Validator for Deck
Attributes
@!attribute [r] block_height
the Deck's block_height
@return [Integer]
@example
deck.block_height #=> 939237
@api public
@!attribute [r] cards the Deck's cards
@return [Array<ZombieBattleground::Api::Models::SimpleCard>]
@example
deck.cards #=> [ZombieBattleground::Api::Models::SimpleCard]
@api public
@!attribute [r] created_at
the Deck's created_at
time
@return [Time]
@example
deck.created_at #=> Time
@api public
@!attribute [r] id Deck's id
@return [Integer]
@example
deck.id #=> 1812
@api public
@!attribute [r] is_deleted
the Deck's is_deleted
@return [Boolean]
@example
deck.is_deleted #=> false
@api public
@!attribute [r] name the Deck's name
@return [String]
@example
deck.name #=> "Leaf Midrange"
@api public
@!attribute [r] primary_skill_id
the Deck's primary_skill_id
@return [Integer]
@example
deck.primary_skill_id #=> 19
@api public
@!attribute [r] secondary_skill_id
the Deck's secondary_skill_id
@return [Integer]
@example
deck.secondary_skill_id #=> 18
@api public
@!attribute [r] sender_address
the Deck's sender_address
@return [String]
@example
deck.sender_address #=> "0x62bb8C4452c3Fa7E9eEd6D9Ceaa4d3fe8E18E249"
@api public
@!attribute [r] updated_at
the Deck's updated_at
time
@return [Time]
@example
deck.updated_at #=> Time
@api public
@!attribute [r] version the Deck's version
@return [String]
@example
deck.version #=> "v5"
@api public
Public Class Methods
Creates a new Deck
@param card [Hash] Parsed JSON response
@return [ZombieBattleground::Api::Deck]
@example
deck = ZombieBattleground::Api::Deck.new(parsed_json) # => ZombieBattleground::Api::Deck
@api public
# File lib/zombie_battleground/api/models/deck.rb, line 213 def initialize(deck) deck.each do |key, value| next if value.nil? # this is an illegal response, deck id 1 is bogus if key == 'cards' instance_variable_set( "@#{key}".to_sym, value.map { |card| ZombieBattleground::Api::Models::SimpleCard.new(card) } ) elsif %w[created_at updated_at].include?(key) instance_variable_set("@#{key}".to_sym, Time.parse(value)) else instance_variable_set("@#{key}".to_sym, value) end end end
Private Instance Methods
Validator for correct number of cards in deck
@return [void]
@api private
# File lib/zombie_battleground/api/models/deck.rb, line 261 def cards_has_required_count return if errors.messages.size.zero? && cards.sum(&:amount) == DECK_REQUIRED_CARDS_COUNT errors.add(:cards, 'cards must add up to 30') end
Validator for cards attribute
@return [void]
@api private
# File lib/zombie_battleground/api/models/deck.rb, line 237 def cards_is_an_array_of_simple_card unless @cards.is_a?(Array) errors.add(:cards, 'cards must be an Array') return end @cards.each do |card| next if card.is_a?(ZombieBattleground::Api::Models::SimpleCard) && card.valid? && card.errors.size.zero? errors.add(:cards, 'cards must be an array of SimpleCard') break end cards_has_required_count end