Class: Oakdex::Pokemon::Factory

Inherits:
Object
  • Object
show all
Defined in:
lib/oakdex/pokemon/factory.rb

Overview

Creates Pokemon instance and prefills attributes

Constant Summary collapse

REQUIRED_ATTRIBUTES =
%i[exp gender ability_id nature_id hp iv ev moves]
OPTIONAL_ATTRIBUTES =
%i[
  original_trainer
  primary_status_condition
  wild
  item_id
  amie
  friendship
]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(species, options = {}) ⇒ Factory

Returns a new instance of Factory.



26
27
28
29
# File 'lib/oakdex/pokemon/factory.rb', line 26

def initialize(species, options = {})
  @species = species
  @options = options
end

Class Method Details

.create(species, options = {}) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/oakdex/pokemon/factory.rb', line 16

def create(species, options = {})
  factory = new(species, options)
  attributes = Hash[(REQUIRED_ATTRIBUTES +
    OPTIONAL_ATTRIBUTES).map do |attr|
                      [attr, factory.send(attr)]
                    end]
  Pokemon.new(species.names['en'], attributes)
end