Class: Oakdex::Pokemon::Import
- Inherits:
-
Object
- Object
- Oakdex::Pokemon::Import
- Defined in:
- lib/oakdex/pokemon/import.rb
Overview
Imports and validates pokemon
Class Method Summary collapse
Instance Method Summary collapse
- #import! ⇒ Object
-
#initialize(data) ⇒ Import
constructor
A new instance of Import.
Constructor Details
#initialize(data) ⇒ Import
Returns a new instance of Import.
14 15 16 |
# File 'lib/oakdex/pokemon/import.rb', line 14 def initialize(data) @data = data.is_a?(Hash) ? data : JSON.parse(data) end |
Class Method Details
Instance Method Details
#import! ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/oakdex/pokemon/import.rb', line 18 def import! JSON::Validator.validate!(self.class.schema, @data) pok = Oakdex::Pokemon.new(@data['species_id'], attributes) apply_growth_events(pok) pok rescue JSON::Schema::ValidationError => e raise Oakdex::Pokemon::InvalidPokemon, e. rescue Oakdex::Pokedex::NotFound => e raise Oakdex::Pokemon::InvalidPokemon, e. end |