Class: MtgRb::Expansion
- Inherits:
-
Object
- Object
- MtgRb::Expansion
- Defined in:
- lib/mtg_rb/expansion.rb
Overview
This is a set of magic cards that was released together. They’re unique by name. They also have a three-character shortcode.
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#border ⇒ Object
readonly
Returns the value of attribute border.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#online_only ⇒ Object
readonly
Returns the value of attribute online_only.
-
#printings ⇒ Object
readonly
Returns the value of attribute printings.
-
#release_date ⇒ Object
readonly
Returns the value of attribute release_date.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name:, code:, release_date:, border:, block:, type:, online_only:, printings:) ⇒ Expansion
constructor
A new instance of Expansion.
Constructor Details
#initialize(name:, code:, release_date:, border:, block:, type:, online_only:, printings:) ⇒ Expansion
Returns a new instance of Expansion.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/mtg_rb/expansion.rb', line 33 def initialize(name:, code:, release_date:, border:, block:, type:, online_only:, printings:) @name = name @code = code @release_date = release_date @border = border @block = block @type = type @online_only = online_only @printings = printings end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
31 32 33 |
# File 'lib/mtg_rb/expansion.rb', line 31 def block @block end |
#border ⇒ Object (readonly)
Returns the value of attribute border.
31 32 33 |
# File 'lib/mtg_rb/expansion.rb', line 31 def border @border end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
31 32 33 |
# File 'lib/mtg_rb/expansion.rb', line 31 def code @code end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
31 32 33 |
# File 'lib/mtg_rb/expansion.rb', line 31 def name @name end |
#online_only ⇒ Object (readonly)
Returns the value of attribute online_only.
31 32 33 |
# File 'lib/mtg_rb/expansion.rb', line 31 def online_only @online_only end |
#printings ⇒ Object (readonly)
Returns the value of attribute printings.
31 32 33 |
# File 'lib/mtg_rb/expansion.rb', line 31 def printings @printings end |
#release_date ⇒ Object (readonly)
Returns the value of attribute release_date.
31 32 33 |
# File 'lib/mtg_rb/expansion.rb', line 31 def release_date @release_date end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
31 32 33 |
# File 'lib/mtg_rb/expansion.rb', line 31 def type @type end |
Class Method Details
.from_hash(expansion_hash) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/mtg_rb/expansion.rb', line 8 def self.from_hash(expansion_hash) release_date = if expansion_hash.key?("releaseDate") Date.strptime(expansion_hash.fetch("releaseDate"), "%Y-%m-%d") else nil end self.new({ name: expansion_hash.fetch("name"), code: expansion_hash.fetch("code"), release_date: release_date, border: expansion_hash.fetch("border"), block: expansion_hash.fetch("block", nil), type: expansion_hash.fetch("type", nil), online_only: expansion_hash.fetch("onlineOnly", false), printings: [], # will be added later }) rescue KeyError => err p err p expansion_hash end |