Class: MtgRb::Card

Inherits:
Object
  • Object
show all
Defined in:
lib/mtg_rb/card.rb

Overview

Cards have costs, types, and rules text. They are “reified” by one or more printings. They belong to expansions through those printings.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, names:, mana_cost:, converted_mana_cost:, colors:, color_identity:, type:, supertypes:, types:, subtypes:, text:, power:, toughness:, loyalty:, printings:) ⇒ Card



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/mtg_rb/card.rb', line 31

def initialize(name:, names:, mana_cost:,converted_mana_cost:,colors:,color_identity:,type:,supertypes:,types:,subtypes:,text:,power:,toughness:,loyalty:, printings:)
  @name = name
  @names = names
  @mana_cost = mana_cost
  @converted_mana_cost = converted_mana_cost
  @colors = colors
  @color_identity = color_identity
  @type = type
  @supertypes = supertypes
  @types = types
  @subtypes = subtypes
  @text = text
  @power = power
  @toughness = toughness
  @loyalty = loyalty
  @printings = printings
end

Instance Attribute Details

#color_identityObject (readonly)

Returns the value of attribute color_identity.



29
30
31
# File 'lib/mtg_rb/card.rb', line 29

def color_identity
  @color_identity
end

#colorsObject (readonly)

Returns the value of attribute colors.



29
30
31
# File 'lib/mtg_rb/card.rb', line 29

def colors
  @colors
end

#converted_mana_costObject (readonly)

Returns the value of attribute converted_mana_cost.



29
30
31
# File 'lib/mtg_rb/card.rb', line 29

def converted_mana_cost
  @converted_mana_cost
end

#loyaltyObject (readonly)

Returns the value of attribute loyalty.



29
30
31
# File 'lib/mtg_rb/card.rb', line 29

def loyalty
  @loyalty
end

#mana_costObject (readonly)

Returns the value of attribute mana_cost.



29
30
31
# File 'lib/mtg_rb/card.rb', line 29

def mana_cost
  @mana_cost
end

#nameObject (readonly)

Returns the value of attribute name.



29
30
31
# File 'lib/mtg_rb/card.rb', line 29

def name
  @name
end

#namesObject (readonly)

Returns the value of attribute names.



29
30
31
# File 'lib/mtg_rb/card.rb', line 29

def names
  @names
end

#powerObject (readonly)

Returns the value of attribute power.



29
30
31
# File 'lib/mtg_rb/card.rb', line 29

def power
  @power
end

#printingsObject (readonly)

Returns the value of attribute printings.



29
30
31
# File 'lib/mtg_rb/card.rb', line 29

def printings
  @printings
end

#subtypesObject (readonly)

Returns the value of attribute subtypes.



29
30
31
# File 'lib/mtg_rb/card.rb', line 29

def subtypes
  @subtypes
end

#supertypesObject (readonly)

Returns the value of attribute supertypes.



29
30
31
# File 'lib/mtg_rb/card.rb', line 29

def supertypes
  @supertypes
end

#textObject (readonly)

Returns the value of attribute text.



29
30
31
# File 'lib/mtg_rb/card.rb', line 29

def text
  @text
end

#toughnessObject (readonly)

Returns the value of attribute toughness.



29
30
31
# File 'lib/mtg_rb/card.rb', line 29

def toughness
  @toughness
end

#typeObject (readonly)

Returns the value of attribute type.



29
30
31
# File 'lib/mtg_rb/card.rb', line 29

def type
  @type
end

#typesObject (readonly)

Returns the value of attribute types.



29
30
31
# File 'lib/mtg_rb/card.rb', line 29

def types
  @types
end

Class Method Details

.from_hash(card_hash) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/mtg_rb/card.rb', line 6

def self.from_hash(card_hash)
  self.new(
    name: card_hash.fetch("name"),
    names: card_hash.fetch("names", nil),
    mana_cost: card_hash.fetch("manaCost", nil), # double-faced can have no mana cost
    converted_mana_cost: card_hash.fetch("cmc", nil),
    colors: card_hash.fetch("colors", []),
    color_identity: card_hash.fetch("colorIdentity", []),
    type: card_hash.fetch("type"),
    supertypes: card_hash.fetch("supertypes", []),
    types: card_hash.fetch("types", []), # Unglued Tokens
    subtypes: card_hash.fetch("subtypes", []),
    text: card_hash.fetch("text", ""),
    power: card_hash.fetch("power", nil),
    toughness: card_hash.fetch("toughness", nil),
    loyalty: card_hash.fetch("loyalty", nil),
    printings: [], # will be added later
  )
rescue KeyError => err
  p err
  p card_hash
end