Sha256: 05921e287eb4060d4b9cca58b7a0a96c45e552eb3cb6f5751c478c916764a1e3
Contents?: true
Size: 1.34 KB
Versions: 89
Compression:
Stored size: 1.34 KB
Contents
module Eco module API module Organization class PersonSchemas < Eco::Language::Models::Collection # build the shortcuts of Collection attr_collection :id, :name def initialize(schemas = [], klass: Ecoportal::API::Internal::PersonSchema) @klass = Ecoportal::API::Internal::PersonSchema @caches_init = false super(schemas, klass: @klass) init_caches end def to_id(name) case name when Enumerable name.map do |n| schema(n)&.id end.compact else schema(name)&.id end end def to_name(id) schema(id)&.name end def schema(id_name) @by_id.fetch(schema_id(id_name), nil) end private def schema_name(id_name) (@by_id[id_name] || @by_name[id_name&.downcase])&.name&.downcase end def schema_id(id_name) (@by_name[id_name&.downcase] || @by_id[id_name])&.id end 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 end end end end
Version data entries
89 entries across 89 versions & 1 rubygems