pokemon.rb 594 B

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