mtg_rb 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +13 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/mtg_rb.rb +6 -0
- data/lib/mtg_rb/artist.rb +10 -0
- data/lib/mtg_rb/card.rb +49 -0
- data/lib/mtg_rb/expansion.rb +44 -0
- data/lib/mtg_rb/multiverse.rb +49 -0
- data/lib/mtg_rb/printing.rb +41 -0
- data/lib/mtg_rb/version.rb +3 -0
- data/mtg_rb.gemspec +22 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 892c6231d74195ad76ae1c8f2af32f7c9bda42f7
|
4
|
+
data.tar.gz: 4fa48a13ed306999cfb93d4f4ffd90bea5e7179c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 931b69ba271768f6950cd25eb63db85a123c4473de3588de7d1f647360a48e576e1fc331c909acbe918d194392460206e54ff0b5b3c64acdf0cea20a7678080d
|
7
|
+
data.tar.gz: 07ce1cc18aa98b723935f91ff688ce1f08ef0f8f60f59ab0dbca535eedc5ac39e17c9636175c1c58585d57e2cc7779375fdcf12678f6a5580fd2beff419d17c0
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Robert Mosolgo
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# MtgRb
|
2
|
+
|
3
|
+
Normalize `MTGJSON` into a coherent, normalized Ruby object tree.
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
mtg_json_path = File.expand_path("../path/to/AllSets-x.json", __FILE__)
|
7
|
+
mtg_json_hash = JSON.parse(File.read(mtg_json_path))
|
8
|
+
MULTIVERSE = MtgRb::Multiverse.from_hash(mtg_json_hash)
|
9
|
+
MULTIVERSE.expansions["Conflux"] # => Expansion instance
|
10
|
+
MULTIVERSE.cards["Icy Manipulator"] # => Card instance
|
11
|
+
```
|
12
|
+
|
13
|
+
`Card` and `Expansion` are joined by `Printing`.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "mtg_rb"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/mtg_rb.rb
ADDED
data/lib/mtg_rb/card.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
module MtgRb
|
2
|
+
# Cards have costs, types, and rules text.
|
3
|
+
# They are "reified" by one or more printings.
|
4
|
+
# They belong to expansions through those printings.
|
5
|
+
class Card
|
6
|
+
def self.from_hash(card_hash)
|
7
|
+
self.new(
|
8
|
+
name: card_hash.fetch("name"),
|
9
|
+
names: card_hash.fetch("names", nil),
|
10
|
+
mana_cost: card_hash.fetch("manaCost", nil), # double-faced can have no mana cost
|
11
|
+
converted_mana_cost: card_hash.fetch("cmc", nil),
|
12
|
+
colors: card_hash.fetch("colors", []),
|
13
|
+
color_identity: card_hash.fetch("colorIdentity", []),
|
14
|
+
type: card_hash.fetch("type"),
|
15
|
+
supertypes: card_hash.fetch("supertypes", []),
|
16
|
+
types: card_hash.fetch("types", []), # Unglued Tokens
|
17
|
+
subtypes: card_hash.fetch("subtypes", []),
|
18
|
+
text: card_hash.fetch("text", ""),
|
19
|
+
power: card_hash.fetch("power", nil),
|
20
|
+
toughness: card_hash.fetch("toughness", nil),
|
21
|
+
loyalty: card_hash.fetch("loyalty", nil),
|
22
|
+
printings: [], # will be added later
|
23
|
+
)
|
24
|
+
rescue KeyError => err
|
25
|
+
p err
|
26
|
+
p card_hash
|
27
|
+
end
|
28
|
+
|
29
|
+
attr_reader :name, :names, :mana_cost, :converted_mana_cost, :colors, :color_identity, :type, :supertypes, :types, :subtypes, :text, :power, :toughness, :loyalty, :printings
|
30
|
+
|
31
|
+
def initialize(name:, names:, mana_cost:,converted_mana_cost:,colors:,color_identity:,type:,supertypes:,types:,subtypes:,text:,power:,toughness:,loyalty:, printings:)
|
32
|
+
@name = name
|
33
|
+
@names = names
|
34
|
+
@mana_cost = mana_cost
|
35
|
+
@converted_mana_cost = converted_mana_cost
|
36
|
+
@colors = colors
|
37
|
+
@color_identity = color_identity
|
38
|
+
@type = type
|
39
|
+
@supertypes = supertypes
|
40
|
+
@types = types
|
41
|
+
@subtypes = subtypes
|
42
|
+
@text = text
|
43
|
+
@power = power
|
44
|
+
@toughness = toughness
|
45
|
+
@loyalty = loyalty
|
46
|
+
@printings = printings
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require "date"
|
2
|
+
|
3
|
+
module MtgRb
|
4
|
+
# This is a set of magic cards that was released together.
|
5
|
+
# They're unique by name. They also have a three-character shortcode.
|
6
|
+
class Expansion
|
7
|
+
# @param [Hash] An entry in AllSets.json
|
8
|
+
def self.from_hash(expansion_hash)
|
9
|
+
|
10
|
+
release_date = if expansion_hash.key?("releaseDate")
|
11
|
+
Date.strptime(expansion_hash.fetch("releaseDate"), "%Y-%m-%d")
|
12
|
+
else
|
13
|
+
nil
|
14
|
+
end
|
15
|
+
|
16
|
+
self.new({
|
17
|
+
name: expansion_hash.fetch("name"),
|
18
|
+
code: expansion_hash.fetch("code"),
|
19
|
+
release_date: release_date,
|
20
|
+
border: expansion_hash.fetch("border"),
|
21
|
+
block: expansion_hash.fetch("block", nil),
|
22
|
+
type: expansion_hash.fetch("type", nil),
|
23
|
+
online_only: expansion_hash.fetch("onlineOnly", false),
|
24
|
+
printings: [], # will be added later
|
25
|
+
})
|
26
|
+
rescue KeyError => err
|
27
|
+
p err
|
28
|
+
p expansion_hash
|
29
|
+
end
|
30
|
+
|
31
|
+
attr_reader :name, :code, :release_date, :border, :block, :type, :online_only, :printings
|
32
|
+
|
33
|
+
def initialize(name:, code:, release_date:, border:, block:, type:, online_only:, printings:)
|
34
|
+
@name = name
|
35
|
+
@code = code
|
36
|
+
@release_date = release_date
|
37
|
+
@border = border
|
38
|
+
@block = block
|
39
|
+
@type = type
|
40
|
+
@online_only = online_only
|
41
|
+
@printings = printings
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module MtgRb
|
2
|
+
# A multiverse contains cards, expansions, printings, etc
|
3
|
+
# It is the entry point for the data and can be created from MTGJSON.
|
4
|
+
class Multiverse
|
5
|
+
# @param [Hash] The result of parsing AllSets.json
|
6
|
+
# @return [Multiverse] A populated multiverse from JSON
|
7
|
+
def self.from_hash(all_expansions)
|
8
|
+
|
9
|
+
# {name => object} lookup tables
|
10
|
+
cards_cache = {}
|
11
|
+
artists_cache = {}
|
12
|
+
expansions_cache = {}
|
13
|
+
|
14
|
+
all_expansions.each do |expansion_code, expansion_hash|
|
15
|
+
expansion = MtgRb::Expansion.from_hash(expansion_hash)
|
16
|
+
expansion_hash.fetch("cards").each do |card_hash|
|
17
|
+
card_name = card_hash.fetch("name")
|
18
|
+
card = cards_cache[card_name] ||= MtgRb::Card.from_hash(card_hash)
|
19
|
+
artist_name = card_hash.fetch("artist")
|
20
|
+
artist = artists_cache[artist_name] ||= MtgRb::Artist.new(name: artist_name, printings: [])
|
21
|
+
printing = MtgRb::Printing.from_card_hash(
|
22
|
+
expansion: expansion,
|
23
|
+
card: card,
|
24
|
+
artist: artist,
|
25
|
+
card_hash: card_hash,
|
26
|
+
)
|
27
|
+
card.printings << printing
|
28
|
+
artist.printings << printing
|
29
|
+
expansion.printings << printing
|
30
|
+
end
|
31
|
+
expansions_cache[expansion.name] = expansion
|
32
|
+
end
|
33
|
+
|
34
|
+
self.new({
|
35
|
+
cards: cards_cache,
|
36
|
+
artists: artists_cache,
|
37
|
+
expansions: expansions_cache,
|
38
|
+
})
|
39
|
+
end
|
40
|
+
|
41
|
+
attr_reader :cards, :artists, :expansions
|
42
|
+
|
43
|
+
def initialize(cards:, artists:, expansions:)
|
44
|
+
@cards = cards
|
45
|
+
@artists = artists
|
46
|
+
@expansions = expansions
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module MtgRb
|
2
|
+
# This joins some ideas together in "concrete" piece of paper.
|
3
|
+
# - Card
|
4
|
+
# - Expansion
|
5
|
+
# - Artist
|
6
|
+
#
|
7
|
+
# Some attributes come in "Cards" from MTGJSON but really belong to the printing.
|
8
|
+
# - Number
|
9
|
+
# - Flavor text
|
10
|
+
# - Artist
|
11
|
+
# - Rarity
|
12
|
+
# - ?? others?
|
13
|
+
class Printing
|
14
|
+
def self.from_card_hash(expansion:, card:, artist:, card_hash:)
|
15
|
+
self.new(
|
16
|
+
card: card,
|
17
|
+
expansion: expansion,
|
18
|
+
artist: artist,
|
19
|
+
flavor: card_hash.fetch("flavor", ""),
|
20
|
+
rarity: card_hash.fetch("rarity"),
|
21
|
+
number: card_hash.fetch("number", nil),
|
22
|
+
multiverseid: card_hash.fetch("multiverseid", nil),
|
23
|
+
)
|
24
|
+
rescue KeyError => err
|
25
|
+
p err
|
26
|
+
p card_hash
|
27
|
+
end
|
28
|
+
|
29
|
+
attr_reader :card, :expansion, :artist, :flavor, :rarity, :number, :multiverseid
|
30
|
+
|
31
|
+
def initialize(card:, expansion:, artist:, flavor:, rarity:, number:, multiverseid:)
|
32
|
+
@card = card
|
33
|
+
@expansion = expansion
|
34
|
+
@artist = artist
|
35
|
+
@flavor = flavor
|
36
|
+
@rarity = rarity
|
37
|
+
@number = number
|
38
|
+
@multiverseid = multiverseid
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/mtg_rb.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mtg_rb/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mtg_rb"
|
8
|
+
spec.version = MtgRb::VERSION
|
9
|
+
spec.authors = ["Robert Mosolgo"]
|
10
|
+
spec.email = ["rdmosolgo@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Parse MTGJSON and build a tree of Ruby objects}
|
13
|
+
spec.homepage = "https://github.com/rmosolgo/mtg_rb"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
20
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
21
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mtg_rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robert Mosolgo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- rdmosolgo@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".travis.yml"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/console
|
69
|
+
- bin/setup
|
70
|
+
- lib/mtg_rb.rb
|
71
|
+
- lib/mtg_rb/artist.rb
|
72
|
+
- lib/mtg_rb/card.rb
|
73
|
+
- lib/mtg_rb/expansion.rb
|
74
|
+
- lib/mtg_rb/multiverse.rb
|
75
|
+
- lib/mtg_rb/printing.rb
|
76
|
+
- lib/mtg_rb/version.rb
|
77
|
+
- mtg_rb.gemspec
|
78
|
+
homepage: https://github.com/rmosolgo/mtg_rb
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 2.5.1
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: Parse MTGJSON and build a tree of Ruby objects
|
102
|
+
test_files: []
|