pokemon.rb 736 B

12345678910111213141516171819202122232425262728293031
  1. # frozen_string_literal: true
  2. module PKParse
  3. # Define a PKParse::Pokemon to keep Rails' model distinct and allow this to be
  4. # updated independently without fear of breaking the app.
  5. class Pokemon
  6. attr_accessor :pokedex_number, :nickname, :raw_nickname, :raw_pokemon
  7. def initialize(attributes = {})
  8. attributes.each do |attr, v|
  9. send("#{attr}=", v)
  10. rescue StandardError
  11. PKParse.logger.error("Received unexpected attribute '#{attr}'")
  12. nil
  13. end
  14. end
  15. def to_h
  16. {
  17. pokedex_number: pokedex_number,
  18. nickname: nickname,
  19. raw_nickname: raw_nickname,
  20. raw_pokemon: raw_pokemon,
  21. }
  22. end
  23. def to_json(*_args)
  24. to_h
  25. end
  26. end
  27. end