pokemon.rb 664 B

123456789101112131415161718192021222324252627282930
  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. nil
  12. end
  13. end
  14. def to_h
  15. {
  16. pokedex_number: pokedex_number,
  17. nickname: nickname,
  18. raw_nickname: raw_nickname,
  19. raw_pokemon: raw_pokemon,
  20. }
  21. end
  22. def to_json(*_args)
  23. to_h
  24. end
  25. end
  26. end