pokemon.rb 625 B

12345678910111213141516171819202122232425262728
  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) rescue nil
  10. end
  11. end
  12. def to_h
  13. {
  14. pokedex_number: pokedex_number,
  15. nickname: nickname,
  16. raw_nickname: raw_nickname,
  17. raw_pokemon: raw_pokemon,
  18. }
  19. end
  20. def to_json
  21. to_h
  22. end
  23. end
  24. end