Class: Ecoportal::API::V1::PersonDetails
Instance Attribute Summary
#doc
Instance Method Summary
collapse
#as_update, build, #initialize, passthrough, #print, #to_json
Instance Method Details
#[](id) ⇒ Object
37
38
39
|
# File 'lib/ecoportal/api/v1/person_details.rb', line 37
def [](id)
get_field(id)&.value
end
|
#[]=(id, value) ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/ecoportal/api/v1/person_details.rb', line 41
def []=(id, value)
if field = get_field(id)
field.value = value
else
raise "details[#{id.inspect}] is missing. Did you forget to load the schema?"
end
end
|
#as_json ⇒ Object
7
8
9
|
# File 'lib/ecoportal/api/v1/person_details.rb', line 7
def as_json
super.merge "fields" => fields.map(&:as_json)
end
|
#fields ⇒ Object
16
17
18
19
20
21
|
# File 'lib/ecoportal/api/v1/person_details.rb', line 16
def fields
return @fields if defined?(@fields)
@fields = (doc["fields"] || []).map do |field|
schema_field_value_class.new(field)
end
end
|
#get_field(id) ⇒ Object
32
33
34
35
|
# File 'lib/ecoportal/api/v1/person_details.rb', line 32
def get_field(id)
@fields_by_id or index_fields
@fields_by_id[id] || @fields_by_alt_id[id]
end
|
#index_fields ⇒ Object
23
24
25
26
27
28
29
30
|
# File 'lib/ecoportal/api/v1/person_details.rb', line 23
def index_fields
@fields_by_id = {}
@fields_by_alt_id = {}
fields.each do |wrapped|
@fields_by_id[wrapped.id] = wrapped
@fields_by_alt_id[wrapped.alt_id] = wrapped
end
end
|
#schema_id=(value) ⇒ Object
11
12
13
14
|
# File 'lib/ecoportal/api/v1/person_details.rb', line 11
def schema_id=(value)
@fields = [] if value.nil?
doc["schema_id"] = value
end
|