Module: RecordChildren::ClassMethods

Defined in:
frontend/app/models/mixins/record_children.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) child_type



13
14
15
# File 'frontend/app/models/mixins/record_children.rb', line 13

def child_type
  JSONModel.parse_jsonmodel_ref(self.schema['properties']['children']['items']['type']).first
end

- (Object) clean(child)



60
61
62
63
# File 'frontend/app/models/mixins/record_children.rb', line 60

def clean(child)
  clean_dates(child)
  clean_notes(child)
end

- (Object) clean_dates(child)



24
25
26
27
28
29
30
31
32
# File 'frontend/app/models/mixins/record_children.rb', line 24

def clean_dates(child)
  if child["dates"]
    if child["dates"][0].reject{|k,v| v.blank?}.empty?
      child.delete("dates")
    elsif child["dates"][0]["label"].empty?
      child["dates"][0]["label"] = "other"
    end
  end
end

- (Object) clean_notes(child)



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'frontend/app/models/mixins/record_children.rb', line 34

def clean_notes(child)
  if child["notes"]
    (0..2).each do |i|
      if not child["notes"][i]["type"].blank?
        note_types_for_child.each do |notetype|
          if JSONModel.enum_values(JSONModel(notetype).schema['properties']['type']['dynamic_enum']).include?(child["notes"][i]["type"])
            child["notes"][i]["jsonmodel_type"] = notetype.to_s
          end
        end

        child["notes"][i]["publish"] = true

        # Multipart and biog/hist notes use a 'text' subnote type for their content.
        if ['note_multipart', 'note_bioghist'].include?(child["notes"][i]["jsonmodel_type"])
          child["notes"][i]["subnotes"] = [{"jsonmodel_type" => "note_text",
                                            "content" => child["notes"][i]["content"].join(" ")}]
        end

      elsif child["notes"][i]["type"].blank? and child["notes"][i]["content"][0].blank?
        child["notes"][i] = nil
      end
    end
    child["notes"].compact!
  end
end

- (Object) from_hash(hash, raise_errors = true, trusted = false)



65
66
67
68
69
# File 'frontend/app/models/mixins/record_children.rb', line 65

def from_hash(hash, raise_errors = true, trusted = false)
  hash["children"].each {|child| clean(child)}

  super
end

- (Object) note_types_for_child



18
19
20
21
22
# File 'frontend/app/models/mixins/record_children.rb', line 18

def note_types_for_child
  JSONModel(child_type).schema['properties']['notes']['items']['type'].map {|ref|
    JSONModel.parse_jsonmodel_ref(ref['type']).first
  }
end