class Eco::API::Organization::PersonSchemas

Public Class Methods

new(schemas = [], klass: Ecoportal::API::Internal::PersonSchema) click to toggle source
Calls superclass method Eco::Language::Models::Collection::new
# File lib/eco/api/organization/person_schemas.rb, line 8
def initialize(schemas = [], klass: Ecoportal::API::Internal::PersonSchema)
  @klass       = Ecoportal::API::Internal::PersonSchema
  @caches_init = false
  super(schemas, klass: @klass)
  init_caches
end

Public Instance Methods

[](id_name) click to toggle source
# File lib/eco/api/organization/person_schemas.rb, line 34
def [](id_name)
  @by_id[schema_id(id_name)]
end
schema(id_name) click to toggle source
# File lib/eco/api/organization/person_schemas.rb, line 30
def schema(id_name)
  self[id_name]
end
to_id(name) click to toggle source
# File lib/eco/api/organization/person_schemas.rb, line 15
def to_id(name)
  case name
  when Enumerable
    name.map do |n|
      schema(n)&.id
    end.compact
  else
    schema(name)&.id
  end
end
to_name(id) click to toggle source
# File lib/eco/api/organization/person_schemas.rb, line 26
def to_name(id)
  schema(id)&.name
end

Private Instance Methods

init_caches() click to toggle source
# File lib/eco/api/organization/person_schemas.rb, line 48
def init_caches
  return if @caches_init
  @by_id   = self.map { |pg| [pg.id, pg] }.to_h
  @by_name = self.map { |pg| [pg.name&.downcase, pg] }.to_h
  @caches_init = true
end
schema_id(id_name) click to toggle source
# File lib/eco/api/organization/person_schemas.rb, line 44
def schema_id(id_name)
  (@by_name[id_name&.downcase] || @by_id[id_name])&.id
end
schema_name(id_name) click to toggle source
# File lib/eco/api/organization/person_schemas.rb, line 40
def schema_name(id_name)
  (@by_id[id_name] || @by_name[id_name&.downcase])&.name&.downcase
end