Module: RecordChildren::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

#child_typeObject



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

#clean(child) ⇒ Object



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

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

#clean_dates(child) ⇒ Object



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

#clean_notes(child) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# 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

        # 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(" "),
                                            "publish" => child["notes"][i]["publish"]}]
        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

#from_hash(hash, raise_errors = true, trusted = false) ⇒ Object



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

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

  super
end

#note_types_for_childObject



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