Project

mtg_rb

0.0
No commit activity in last 3 years
No release in over 3 years
Parse MTGJSON and build a tree of Ruby objects
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.11
~> 5.0
~> 10.0
 Project Readme

MtgRb

Card objects from MTGJSON

Normalize MTGJSON into a coherent, normalized Ruby object tree.

mtg_json_path = File.expand_path("../path/to/AllSets-x.json", __FILE__)
mtg_json_hash = JSON.parse(File.read(mtg_json_path))
MULTIVERSE = MtgRb::Multiverse.from_hash(mtg_json_hash)
MULTIVERSE.expansions["Conflux"] # => Expansion instance
MULTIVERSE.cards["Icy Manipulator"] # => Card instance

Card and Expansion are joined by Printing.

Manipulate scans

There are places you can get zips of high-quality MTG scans. You can unzip them and write them to new files.

MtgRb::Scans::Migrate.execute(
  # this directory contains `**/ENG*.zip` files of of scans
  from_dir: "~/Downloads/mtg_scans",
  # optional whitelist expansions, defaults to all expansions
  expansion_codes: ["ALA", "CON", "ARB"],
) do |expansion_code, name, entry|
  # This block gets called with each card.
  #
  # In the case of split cards,
  # the block will be called twice with the same entry
  #
  # `entry` is a Zip::Entry from "rubyzip"
  entry.expand("#{expansion_code}/#{name}.jpg")
end