Class: Eversign::Mappings::Document
- Inherits:
-
Object
- Object
- Eversign::Mappings::Document
- Includes:
- Kartograph::DSL
- Defined in:
- lib/eversign/mappings/document.rb
Class Method Summary collapse
- .extract_collection(content, scope) ⇒ Object
- .extract_single(content, scope) ⇒ Object
- .representation_for(document) ⇒ Object
Class Method Details
.extract_collection(content, scope) ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/eversign/mappings/document.rb', line 62 def self.extract_collection(content, scope) data = JSON.parse(content) result = [] data.each do |item| result << extract_single(item.to_json, nil) end result end |
.extract_single(content, scope) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/eversign/mappings/document.rb', line 71 def self.extract_single(content, scope) obj = super(content, scope) data = JSON.parse(content) if data['fields'] data['fields'].each do |field_list| field_data = [] field_list.each do |field| extracted_field = Field.extract_single(field.to_json, nil) field_data << extracted_field if extracted_field end obj.add_field_list(field_data) end end obj end |
.representation_for(document) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/eversign/mappings/document.rb', line 87 def self.representation_for(document) data = super(nil, document) list = [] if document.fields document.fields.each do |field_list| field_data = [] field_list.each do |field| field_data << JSON.parse(Field.representation_for(nil, field)) end list << field_data end end data = JSON.parse(data) data['fields'] = list JSON.dump(data) end |