class ZombieBattleground::Api::Models::Deck

Validator for Deck

Attributes

block_height[R]

@!attribute [r] block_height the Deck's block_height

@return [Integer]

@example

deck.block_height #=> 939237

@api public

cards[R]

@!attribute [r] cards the Deck's cards

@return [Array<ZombieBattleground::Api::Models::SimpleCard>]

@example

deck.cards #=> [ZombieBattleground::Api::Models::SimpleCard]

@api public

created_at[R]

@!attribute [r] created_at the Deck's created_at time

@return [Time]

@example

deck.created_at #=> Time

@api public

deck_id[R]

@!attribute [r] deck_id the Deck's deck_id

@return [Integer]

@example

deck.deck_id #=> 4

@api public

hero_id[R]

@!attribute [r] hero_id the Deck's hero_id

@return [Integer]

@example

deck.hero_id #=> 5

@api public

id[R]

@!attribute [r] id Deck's id

@return [Integer]

@example

deck.id #=> 1812

@api public

is_deleted[R]

@!attribute [r] is_deleted the Deck's is_deleted

@return [Boolean]

@example

deck.is_deleted #=> false

@api public

name[R]

@!attribute [r] name the Deck's name

@return [String]

@example

deck.name #=> "Leaf Midrange"

@api public

primary_skill_id[R]

@!attribute [r] primary_skill_id the Deck's primary_skill_id

@return [Integer]

@example

deck.primary_skill_id #=> 19

@api public

secondary_skill_id[R]

@!attribute [r] secondary_skill_id the Deck's secondary_skill_id

@return [Integer]

@example

deck.secondary_skill_id #=> 18

@api public

sender_address[R]

@!attribute [r] sender_address the Deck's sender_address

@return [String]

@example

deck.sender_address #=> "0x62bb8C4452c3Fa7E9eEd6D9Ceaa4d3fe8E18E249"

@api public

updated_at[R]

@!attribute [r] updated_at the Deck's updated_at time

@return [Time]

@example

deck.updated_at #=> Time

@api public

user_id[R]

@!attribute [r] user_id the Deck's user_id

@return [String]

@example

deck.user_id #=> "ZombieSlayer_5773"

@api public

version[R]

@!attribute [r] version the Deck's version

@return [String]

@example

deck.version #=> "v5"

@api public

Public Class Methods

new(deck) click to toggle source

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

cards_has_required_count() click to toggle source

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
cards_is_an_array_of_simple_card() click to toggle source

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