Module: AssignmentHelpers
- Included in:
- PokeApi::Ability::AbilityEffectChange, PokeApi::ApiResourceList, PokeApi::Common::Encounter, PokeApi::Common::FlavorText, PokeApi::Common::VersionEncounterDetail, PokeApi::EvolutionChain::ChainLink, PokeApi::EvolutionChain::EvolutionDetail, PokeApi::Item::ItemHolderPokemon, PokeApi::LocationArea::EncounterMethodRate, PokeApi::LocationArea::PokemonEncounter, PokeApi::Move::ContestComboDetail, PokeApi::Move::PastMoveStatValue, PokeApi::NamedApiResource, PokeApi::PokeathlonStat::NaturePokeathlonStatAffectSets, PokeApi::Pokemon::LocationAreaEncounter, PokeApi::Pokemon::PokemonHeldItem, PokeApi::Pokemon::PokemonMove, PokeApi::Stat::MoveStatAffectSets, PokeApi::Stat::NatureStatAffectSets, PokeApi::Type::TypeRelations
- Defined in:
- lib/utils/assignment_helpers.rb
Overview
Module housing simple assignment methods/ patterns
Class Method Summary collapse
- .assign_list(data:, klass: nil) ⇒ Object
- .custom_endpoint_object ⇒ Object
- .endpoint_assignment(key:, custom_endpoint_object: {}) ⇒ Object
- .get_named_api_resource_from_url(url) ⇒ Object
- .try_to_assign(data:, klass: nil) ⇒ Object
Class Method Details
.assign_list(data:, klass: nil) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/utils/assignment_helpers.rb', line 5 def assign_list(data:, klass: nil) return unless data data.map do |raw| klass ||= get_named_api_resource_from_url(raw[:url]) klass.new(raw) end end |
.custom_endpoint_object ⇒ Object
21 22 23 |
# File 'lib/utils/assignment_helpers.rb', line 21 def custom_endpoint_object {} end |
.endpoint_assignment(key:, custom_endpoint_object: {}) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/utils/assignment_helpers.rb', line 14 def endpoint_assignment(key:, custom_endpoint_object: {}) singular_key = key.singularize custom_endpoint_object[key] || ENDPOINT_OBJECTS[key] || ENDPOINT_OBJECTS[singular_key] || COMMON_MODELS[key] || COMMON_MODELS[singular_key] end |
.get_named_api_resource_from_url(url) ⇒ Object
32 33 34 35 |
# File 'lib/utils/assignment_helpers.rb', line 32 def get_named_api_resource_from_url(url) key = url.split('/api/v2/').last.split('/').first.tr('-', '_').to_sym ENDPOINT_OBJECTS[key] end |
.try_to_assign(data:, klass: nil) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/utils/assignment_helpers.rb', line 25 def try_to_assign(data:, klass: nil) return unless data klass ||= get_named_api_resource_from_url(data[:url]) klass.new(data) end |