class GathererSetParser::CardParser
Attributes
body[RW]
Public Class Methods
new(card)
click to toggle source
# File lib/gatherer_set_parser/card_parser.rb, line 6 def initialize card @body = card end
Public Instance Methods
attributes()
click to toggle source
# File lib/gatherer_set_parser/card_parser.rb, line 10 def attributes { title: title, card_type: type, sub_type: sub_type, power: power, toughness: toughness, cmc: cmc, mana_cost: mana_cost, loyalty: loyalty, image_url: image_url, text: text, gatherer_url: gatherer_url, rarity: rarity } end
cmc()
click to toggle source
# File lib/gatherer_set_parser/card_parser.rb, line 53 def cmc body.css('.convertedManaCost').text.to_i end
gatherer_url()
click to toggle source
# File lib/gatherer_set_parser/card_parser.rb, line 85 def gatherer_url 'http://gatherer.wizards.com/Pages/' + body.css('.cardTitle > a').attribute('href'). text.gsub(/\.\.\//, '') end
image_url()
click to toggle source
# File lib/gatherer_set_parser/card_parser.rb, line 79 def image_url 'http://gatherer.wizards.com/' + body.css('.leftCol > a > img').attribute('src'). text.gsub(/\.\.\//, '') end
loyalty()
click to toggle source
# File lib/gatherer_set_parser/card_parser.rb, line 57 def loyalty type_box.match(/\(([0-9]*)\)/)[1].to_i rescue nil end
mana_cost()
click to toggle source
# File lib/gatherer_set_parser/card_parser.rb, line 71 def mana_cost array = [] body.css('.manaCost >img').each do |img| array << img.attribute('alt').text.parse_mana_cost end array end
power()
click to toggle source
# File lib/gatherer_set_parser/card_parser.rb, line 45 def power type_box.match(/\(([0-9]*)\//)[1].to_i rescue nil end
rarity()
click to toggle source
# File lib/gatherer_set_parser/card_parser.rb, line 61 def rarity body.css('.rightCol > a').first.children.attribute('alt').text. match(/\((.*)\)/)[1].to_s end
sub_type()
click to toggle source
# File lib/gatherer_set_parser/card_parser.rb, line 38 def sub_type type_box.gsub(/\(.*\)/, ''). match(/ ([a-z0-9 ]*)\z/i)[1].to_s.lstrip.strip rescue nil end
text()
click to toggle source
# File lib/gatherer_set_parser/card_parser.rb, line 66 def text body.xpath('//div[@class="rulesText"]//img[@alt]').each{ |i| i.swap( i['alt'].parse_mana_cost ) } body.css('.rulesText').text.gsub(/[ ]{2,}/, ' ') end
title()
click to toggle source
# File lib/gatherer_set_parser/card_parser.rb, line 25 def title body.css('.cardTitle > a').text end
toughness()
click to toggle source
# File lib/gatherer_set_parser/card_parser.rb, line 49 def toughness type_box.match(/\/([0-9]*)\)/)[1].to_i rescue nil end
type()
click to toggle source
# File lib/gatherer_set_parser/card_parser.rb, line 34 def type type_box.match(/[a-z0-9 ]*/i).to_s.strip end
type_box()
click to toggle source
# File lib/gatherer_set_parser/card_parser.rb, line 29 def type_box body.css('span.typeLine').text. gsub(/\n/, '').gsub(/[ ]{2,}/, ' ').strip.lstrip end