Class: GathererSetParser::CardParser
- Inherits:
-
Object
- Object
- GathererSetParser::CardParser
- Defined in:
- lib/gatherer_set_parser/card_parser.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
Instance Method Summary collapse
- #attributes ⇒ Object
- #cmc ⇒ Object
- #gatherer_url ⇒ Object
- #image_url ⇒ Object
-
#initialize(card) ⇒ CardParser
constructor
A new instance of CardParser.
- #loyalty ⇒ Object
- #mana_cost ⇒ Object
- #power ⇒ Object
- #rarity ⇒ Object
- #sub_type ⇒ Object
- #text ⇒ Object
- #title ⇒ Object
- #toughness ⇒ Object
- #type ⇒ Object
- #type_box ⇒ Object
Constructor Details
#initialize(card) ⇒ CardParser
Returns a new instance of CardParser.
6 7 8 |
# File 'lib/gatherer_set_parser/card_parser.rb', line 6 def initialize card @body = card end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
4 5 6 |
# File 'lib/gatherer_set_parser/card_parser.rb', line 4 def body @body end |
Instance Method Details
#attributes ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# 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 ⇒ Object
53 54 55 |
# File 'lib/gatherer_set_parser/card_parser.rb', line 53 def cmc body.css('.convertedManaCost').text.to_i end |
#gatherer_url ⇒ Object
85 86 87 88 89 |
# 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 ⇒ Object
79 80 81 82 83 |
# 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 ⇒ Object
57 58 59 |
# 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 ⇒ Object
71 72 73 74 75 76 77 |
# 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 ⇒ Object
45 46 47 |
# File 'lib/gatherer_set_parser/card_parser.rb', line 45 def power type_box.match(/\(([0-9]*)\//)[1].to_i rescue nil end |
#rarity ⇒ Object
61 62 63 64 |
# 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 ⇒ Object
38 39 40 41 42 43 |
# 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 ⇒ Object
66 67 68 69 |
# 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 ⇒ Object
25 26 27 |
# File 'lib/gatherer_set_parser/card_parser.rb', line 25 def title body.css('.cardTitle > a').text end |
#toughness ⇒ Object
49 50 51 |
# File 'lib/gatherer_set_parser/card_parser.rb', line 49 def toughness type_box.match(/\/([0-9]*)\)/)[1].to_i rescue nil end |
#type ⇒ Object
34 35 36 |
# 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 ⇒ Object
29 30 31 32 |
# 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 |