Class: MtgRb::Card
- Inherits:
-
Object
- Object
- MtgRb::Card
- 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
-
#color_identity ⇒ Object
readonly
Returns the value of attribute color_identity.
-
#colors ⇒ Object
readonly
Returns the value of attribute colors.
-
#converted_mana_cost ⇒ Object
readonly
Returns the value of attribute converted_mana_cost.
-
#loyalty ⇒ Object
readonly
Returns the value of attribute loyalty.
-
#mana_cost ⇒ Object
readonly
Returns the value of attribute mana_cost.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#names ⇒ Object
readonly
Returns the value of attribute names.
-
#power ⇒ Object
readonly
Returns the value of attribute power.
-
#printings ⇒ Object
readonly
Returns the value of attribute printings.
-
#subtypes ⇒ Object
readonly
Returns the value of attribute subtypes.
-
#supertypes ⇒ Object
readonly
Returns the value of attribute supertypes.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
-
#toughness ⇒ Object
readonly
Returns the value of attribute toughness.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#types ⇒ Object
readonly
Returns the value of attribute types.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name:, names:, mana_cost:, converted_mana_cost:, colors:, color_identity:, type:, supertypes:, types:, subtypes:, text:, power:, toughness:, loyalty:, printings:) ⇒ Card
constructor
A new instance of Card.
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_identity ⇒ Object (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 |
#colors ⇒ Object (readonly)
Returns the value of attribute colors.
29 30 31 |
# File 'lib/mtg_rb/card.rb', line 29 def colors @colors end |
#converted_mana_cost ⇒ Object (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 |
#loyalty ⇒ Object (readonly)
Returns the value of attribute loyalty.
29 30 31 |
# File 'lib/mtg_rb/card.rb', line 29 def loyalty @loyalty end |
#mana_cost ⇒ Object (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 |
#name ⇒ Object (readonly)
Returns the value of attribute name.
29 30 31 |
# File 'lib/mtg_rb/card.rb', line 29 def name @name end |
#names ⇒ Object (readonly)
Returns the value of attribute names.
29 30 31 |
# File 'lib/mtg_rb/card.rb', line 29 def names @names end |
#power ⇒ Object (readonly)
Returns the value of attribute power.
29 30 31 |
# File 'lib/mtg_rb/card.rb', line 29 def power @power end |
#printings ⇒ Object (readonly)
Returns the value of attribute printings.
29 30 31 |
# File 'lib/mtg_rb/card.rb', line 29 def printings @printings end |
#subtypes ⇒ Object (readonly)
Returns the value of attribute subtypes.
29 30 31 |
# File 'lib/mtg_rb/card.rb', line 29 def subtypes @subtypes end |
#supertypes ⇒ Object (readonly)
Returns the value of attribute supertypes.
29 30 31 |
# File 'lib/mtg_rb/card.rb', line 29 def supertypes @supertypes end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
29 30 31 |
# File 'lib/mtg_rb/card.rb', line 29 def text @text end |
#toughness ⇒ Object (readonly)
Returns the value of attribute toughness.
29 30 31 |
# File 'lib/mtg_rb/card.rb', line 29 def toughness @toughness end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
29 30 31 |
# File 'lib/mtg_rb/card.rb', line 29 def type @type end |
#types ⇒ Object (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 |