Class: HearthstoneAPI::CardParser
- Inherits:
-
Object
- Object
- HearthstoneAPI::CardParser
- Defined in:
- lib/hearthstone_api_utils.rb
Constant Summary collapse
- FIND_ALL_URL =
'http://hearthstoneapi.com/cards/findAll'
Instance Method Summary collapse
-
#initialize ⇒ CardParser
constructor
A new instance of CardParser.
- #parse(validate_image_urls = false) ⇒ Object
Constructor Details
#initialize ⇒ CardParser
Returns a new instance of CardParser.
25 26 27 |
# File 'lib/hearthstone_api_utils.rb', line 25 def initialize @cards = JSON.parse `curl "#{FIND_ALL_URL}"` end |
Instance Method Details
#parse(validate_image_urls = false) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/hearthstone_api_utils.rb', line 29 def parse validate_image_urls=false parsed_cards = @cards.dup parsed_cards.each do |card| add_image_url card add_stats card # useful for text searching remove_unwanted_attributes card, 'createdAt', 'updatedAt', 'id' restore_type_value card restore_class_value card restore_quality_value card restore_race_value card end if validate_image_urls raise "Some urls are not valid" unless valid_image_urls?(parsed_cards) end puts "Parsed #{parsed_cards.size} Cards Successfully\nThe first one is:" puts parsed_cards.first parsed_cards end |