Class: Ecoportal::API::V1::PersonSchema

Inherits:
Common::BaseModel show all
Defined in:
lib/ecoportal/api/v1/person_schema.rb

Direct Known Subclasses

Internal::PersonSchema

Instance Attribute Summary

Attributes inherited from Common::BaseModel

#_key, #_parent

Instance Method Summary collapse

Methods inherited from Common::BaseModel

#as_json, #as_update, #consolidate!, #dirty?, #doc, embeds_one, #initial_doc, #initialize, #original_doc, passthrough, #print_pretty, #replace_doc!, #replace_original_doc!, #reset!, #to_json

Methods included from Common::BaseClass

#class_resolver, #redef_without_warning, #resolve_class

Constructor Details

This class inherits a constructor from Ecoportal::API::Common::BaseModel

Instance Method Details

#[](id) ⇒ Object



25
26
27
28
# File 'lib/ecoportal/api/v1/person_schema.rb', line 25

def [](id)
  @fields_by_alt_id or index_fields
  @fields_by_id[id] || @fields_by_alt_id[id]
end

#fieldsObject



10
11
12
13
# File 'lib/ecoportal/api/v1/person_schema.rb', line 10

def fields
  @fields_by_id or index_fields
  @fields_by_id.values
end

#fields_by_alt_idObject



20
21
22
23
# File 'lib/ecoportal/api/v1/person_schema.rb', line 20

def fields_by_alt_id
  @fields_by_alt_id or index_fields
  @fields_by_alt_id
end

#fields_by_idObject



15
16
17
18
# File 'lib/ecoportal/api/v1/person_schema.rb', line 15

def fields_by_id
  @fields_by_id or index_fields
  @fields_by_id
end

#index_fieldsObject



30
31
32
33
34
35
36
37
38
39
# File 'lib/ecoportal/api/v1/person_schema.rb', line 30

def index_fields
  @fields_by_id     = {}
  @fields_by_alt_id = {}

  doc["fields"].each do |field|
    wrapped = schema_field_class.new(field)
    @fields_by_id[wrapped.id] = wrapped
    @fields_by_alt_id[wrapped.alt_id] = wrapped
  end
end

#initialize_details(details) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/ecoportal/api/v1/person_schema.rb', line 41

def initialize_details(details)
  details.schema_id = id
  details.doc["fields"] = fields.map do |field|
    field.doc.slice(*%w[id alt_id name multiple type shared]).merge(
      "value" => field.multiple ? [] : nil
    )
  end
end