Class: MtgRb::Expansion

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#blockObject (readonly)

Returns the value of attribute block.



31
32
33
# File 'lib/mtg_rb/expansion.rb', line 31

def block
  @block
end

#borderObject (readonly)

Returns the value of attribute border.



31
32
33
# File 'lib/mtg_rb/expansion.rb', line 31

def border
  @border
end

#codeObject (readonly)

Returns the value of attribute code.



31
32
33
# File 'lib/mtg_rb/expansion.rb', line 31

def code
  @code
end

#nameObject (readonly)

Returns the value of attribute name.



31
32
33
# File 'lib/mtg_rb/expansion.rb', line 31

def name
  @name
end

#online_onlyObject (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

#printingsObject (readonly)

Returns the value of attribute printings.



31
32
33
# File 'lib/mtg_rb/expansion.rb', line 31

def printings
  @printings
end

#release_dateObject (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

#typeObject (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

Parameters:

  • An (Hash)

    entry in AllSets.json



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