Skip to content

Instantly share code, notes, and snippets.

@krainboltgreene
Created July 23, 2012 02:38
Show Gist options
  • Save krainboltgreene/3161752 to your computer and use it in GitHub Desktop.
Save krainboltgreene/3161752 to your computer and use it in GitHub Desktop.
module MTG
module API
PATH = "http://gatherer.wizards.com/Pages"
SEARCH = "/Search/Default.aspx?output=checklist&action=advanced"
CARD = "/Card/Details.aspx?multiverseid="
MID_SELECTOR = '.nameLink'
MAIN_SELECTOR = '#ctl00_ctl00_ctl00_MainContent_SubContent_SubContent_'
NAME_SELECTOR = MAIN_SELECTOR + 'nameRow .value'
MANA_SELECTOR = MAIN_SELECTOR + 'manaRow .value'
TYPE_SELECTOR = MAIN_SELECTOR + 'typeRow .value'
TEXT_SELECTOR = MAIN_SELECTOR + 'textRow .value'
FLAVOR_SELECTOR = MAIN_SELECTOR + 'flavorRow .value'
STAT_SELECTOR = MAIN_SELECTOR + 'ptRow .value'
RARITY_SELECTOR = MAIN_SELECTOR + 'rarityRow .value'
ARTIST_SELECTOR = MAIN_SELECTOR + 'artistRow .value'
def self.search_uri(expansion)
URI URI.encode PATH + SEARCH + "&set=[\"#{expansion}\"]"
end
def self.card_uri(mid)
URI URI.encode PATH + CARD + mid.to_s
end
end
SETS = {
"Core" => [
"Limited Edition Alpha",
"Limited Edition Beta",
"Unlimited Edition",
"Revised Edition",
"Fourth Edition",
"Fifth Edition",
"Classic Sixth Edition",
"Seventh Edition",
"Eighth Edition",
"Ninth Edition",
"Tenth Edition",
"Magic 2010",
"Magic 2011",
"Magic 2012",
"Magic 2013"
],
"Duel Deck" => [
"Duel Decks: Elves vs. Goblins",
"Duel Decks: Jace vs. Chandra",
"Duel Decks: Divine vs. Demonic",
"Duel Decks: Garruk vs. Liliana",
"Duel Decks: Phyrexia vs. the Coalition",
"Duel Decks: Elspeth vs. Tezzeret",
"Duel Decks: Knights vs. Dragons",
"Duel Decks: Ajani vs. Nicol Bolas",
"Duel Decks: Venser vs. Koth"
],
"From the Vault" => [
"From the Vault: Dragons",
"From the Vault: Exiled",
"From the Vault: Relics",
"From the Vault: Legends",
"From the Vault: Realms"
],
"Premium Deck" => [
"Premium Deck Series: Slivers",
"Premium Deck Series: Fire and Lightning",
"Premium Deck Series: Graveborn"
],
"Master Editions" => [
"Masters Edition",
"Masters Edition II",
"Masters Edition III",
"Masters Edition IV"
],
"Extra" => [
"Chronicles",
"Battle Royale Box Set",
"Beatdown Box Set",
"Planechase",
"Planechase (2012 Edition)",
"Archenemy",
"Commander",
"Time Spiral \"Timeshifted\""
],
"Portal" => [
"Portal",
"Portal Second Age",
"Portal Three Kingdoms"
],
"Starter" => [
"Starter 1999",
"Starter 2000"
],
"Illegal" => [
"Unglued",
"Unhinged",
"Promo set for Gatherer"
],
}
SETS.merge(
"Intro" => SETS["Portal"] + SETS["Starter"],
"Reprint" => SETS["Duel Deck"] + SETS["From the Vault"] + SETS["Premium Deck"] + SETS["Master Editions"] + SETS["Extra"]
)
BLOCKS = {
"Legacy" => [
"Arabian Nights",
"Antiquities",
"Legends",
"The Dark",
"Fallen Empires",
"Homelands"
],
"Ice Age" => [
"Ice Age",
"Alliances",
"Coldsnap"
],
"Mirage" => [
"Mirage",
"Visions",
"Weatherlight"
],
"Tempest" => [
"Tempest",
"Stronghold",
"Exodus"
],
"Urza" => [
"Urza's Saga",
"Urza's Legacy",
"Urza's Destiny"
],
"Masques" => [
"Mercadian Masques",
"Nemesis",
"Prophecy"
],
"Invasion" => [
"Invasion",
"Planeshift",
"Apocalypse"
],
"Odyssey" => [
"Odyssey",
"Torment",
"Judgment"
],
"Onslaught" => [
"Onslaught",
"Legions",
"Scourge"
],
"Mirrodin" => [
"Mirrodin",
"Darksteel",
"Fifth Dawn"
],
"Kamigawa" => [
"Champions of Kamigawa",
"Betrayers of Kamigawa",
"Saviors of Kamigawa"
],
"Ravnica" => [
"Ravnica: City of Guilds",
"Guildpact",
"Dissension"
],
"Time Spiral" => [
"Time Spiral",
"Planar Chaos",
"Future Sight"
],
"Lorwyn" => [
"Lorwyn",
"Morningtide"
],
"Shadowmoor" => [
"Shadowmoor",
"Eventide"
],
"Shards of Alara" => [
"Shards of Alara",
"Conflux",
"Alara Reborn"
],
"Zendikar" => [
"Zendikar",
"Worldwake",
"Rise of the Eldrazi"
],
"Scars of Mirrodin" => [
"Scars of Mirrodin",
"Mirrodin Besieged",
"New Phyrexia"
],
"Innistrad" => [
"Innistrad",
"Dark Ascension",
"Avacyn Restored"
],
}
EXPANSIONS = SETS.merge(BLOCKS).values.flatten
OLD_DESIGN = ["Limited Edition Alpha", "Limited Edition Beta"] + BLOCKS["Legacy"]
FORMATS = {
:standard => SETS["Core"].last(2) + BLOCKS.values.last(2).flatten,
:extended => SETS["Core"].last(2) + BLOCKS.values.last(4).flatten,
:modern => SETS["Core"].last(2) + BLOCKS.values.last(8).flatten,
:legacy => SETS["Core"] + BLOCKS.values.flatten,
:vintage => SETS["Core"] + BLOCKS.values.flatten
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment