class MtgDb::Parsers::DoubleFacedCardDetailsParser
Double-Faced cards have 2x .cardDetails sections, the face-up and face-down cards
Constants
- DEBUG
Attributes
cards[R]
facedown_card_name[R]
faceup_card_name[R]
Public Class Methods
new(uri = nil, response = nil, body = nil, code = nil)
click to toggle source
Calls superclass method
# File lib/mtg_db/parsers.rb, line 172 def initialize(uri = nil, response = nil, body = nil, code = nil) super(uri, response, body, code) @cards = parse_cards @faceup_card_name = @cards.first @facedown_card_name = @cards.last end
Private Instance Methods
cmc(node)
click to toggle source
# File lib/mtg_db/parsers.rb, line 209 def cmc(node) cmc_row = node.search('div.row')[3] cmc_row.search('div.value').text.strip end
mana_cost(node)
click to toggle source
# File lib/mtg_db/parsers.rb, line 203 def mana_cost(node) mana_cost_row = node.search('div.row')[2] img_nodes = mana_cost_row.search('div.value > img') cost = Constants::mana_cost(img_nodes) end
name(node)
click to toggle source
# File lib/mtg_db/parsers.rb, line 198 def name(node) name_row = node.search('div.row')[1] name_row.search('div.value').text.strip end
parse_cards()
click to toggle source
# File lib/mtg_db/parsers.rb, line 181 def parse_cards cards = [] card_nodes = search('.cardDetails') # Each page has 2 cards if it's transformable if card_nodes.size == 2 face_up_name = name(card_nodes.first) # face_up_card = Card.where(:name => face_up_name).first cards << face_up_name face_down_name = name(card_nodes.last) # face_down_card = Card.where(:name => face_down_name).first cards << face_down_name end cards end
subtype(node)
click to toggle source
# File lib/mtg_db/parsers.rb, line 242 def subtype(node) subtype = node.search('span.typeLine').text.split(/\u2014/)[1] unless subtype.nil? subtype.strip! subtype = subtype.partition("\r\n")[0] end subtype end
supertype(node)
click to toggle source
When the supertype is a Vanguard, there is a Hand/Life Modifier and when it's a Planeswalker, there is Loyalty. In either case, no Power/Toughness
# File lib/mtg_db/parsers.rb, line 233 def supertype(node) type_line = node.search('span.typeLine').text.strip supertype = case type_line when /\u2014/ then type_line.split(/\u2014/)[0].strip when /\r\n/ then type_line.split("\r\n")[0].strip else type_line.strip end end
type_data(node)
click to toggle source
# File lib/mtg_db/parsers.rb, line 214 def type_data(node) type_row = node.search('div.row')[4] type = type_row.search('div.value').text.strip type_hash = {} type_hash[:supertype] = Constants::supertype(type) type_hash[:subtype] = Constants::subtype(type) other_data = case type_hash[:supertype] when 'Vanguard' then vanguard_data(node) when 'Planeswalker' then planeswalker_data(node) else {} end type_hash.merge! other_data end