Module: BiologicalAssociation::DwcExtensions

Extended by:
ActiveSupport::Concern
Included in:
BiologicalAssociation
Defined in:
app/models/biological_association/dwc_extensions.rb

Instance Method Summary collapse

Instance Method Details

#darwin_core_extension_jsonObject



37
38
39
# File 'app/models/biological_association/dwc_extensions.rb', line 37

def darwin_core_extension_json

end

#darwin_core_extension_rowObject

Don’t use dwc_



22
23
24
# File 'app/models/biological_association/dwc_extensions.rb', line 22

def darwin_core_extension_row
  Export::Csv::Dwc::Extension::BiologicalAssociations::HEADERS.collect{|h| send( DWC_EXTENSION_MAP[h.to_sym] )}
end


80
81
82
83
84
85
86
87
# File 'app/models/biological_association/dwc_extensions.rb', line 80

def dwc_related_resource
  case biological_association_object.class.base_class.name
  when 'Otu'
    ApplicationController.helpers.label_for_otu(biological_association_object)
  when 'CollectionObject'
    ApplicationController.helpers.label_for_collection_object(biological_association_object)
  end
end


71
72
73
74
75
76
77
78
# File 'app/models/biological_association/dwc_extensions.rb', line 71

def dwc_related_resource_id
  case biological_association_object.class.base_class.name
  when 'Otu'
    biological_association_object.uuid || biological_association_object.uri || biological_association_object.id
  when 'CollectionObject'
    biological_association_object.dwc_occurrence_id
  end
end

#dwc_relationship_according_toObject

TODO: Should reference DOIs, Identifiers, or identifiers in lieu of short citations



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'app/models/biological_association/dwc_extensions.rb', line 90

def dwc_relationship_according_to
  ApplicationController.helpers.short_sources_tag(sources)

  # Could be collectors (ORCID or ...)
  # Could be citation providers

  t = [biological_association_subject_type , biological_association_object_type]

  case t
  when %w{Otu Otu} # Published or nothing
    ApplicationController.helpers.short_sources_tag(sources)
  when %w{CollectionObject Otu} # Assume exists on label
    biological_association_subject.dwc_recorded_by || ApplicationController.helpers.short_sources_tag(sources)
  when %w{Otu CollectionObject} # Assume exists on label
    biological_association_object.dwc_recorded_by || ApplicationController.helpers.short_sources_tag(sources)
  when %w{CollectionObject CollectionObject}
    # Lots of assumptions behind this.  What if specimens were marked as collected in 2 different events, that would be odd
    # but perhaps not impossible
    biological_association_subject.dwc_recorded_by || biological_association_object.dwc_recorded_by
  else
    'BAD DATA: TYPE ERROR'
  end
end

#dwc_relationship_established_dateObject



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'app/models/biological_association/dwc_extensions.rb', line 114

def dwc_relationship_established_date
  t = [biological_association_subject_type , biological_association_object_type]

  case t
  when %w{Otu Otu}
    ApplicationController.helpers.short_sources_year_tag(sources)
  when %w{CollectionObject Otu}
    biological_association_subject.dwc_event_date || ApplicationController.helpers.short_sources_year_tag(sources)
  when %w{Otu CollectionObject}
    biological_association_object.dwc_event_date || ApplicationController.helpers.short_sources_year_tag(sources)
  when %w{CollectionObject CollectionObject}
    # Lots of assumptions behind this.  What if specimens were marked as collected in 2 different events, that would be odd
    # but perhaps not impossible
    biological_association_subject.dwc_event_date || biological_association_object.dwc_event_date
  else
    'BAD DATA: TYPE ERROR'
  end
end

#dwc_relationship_of_resourceObject



67
68
69
# File 'app/models/biological_association/dwc_extensions.rb', line 67

def dwc_relationship_of_resource
  biological_relationship.name
end

#dwc_relationship_of_resource_idObject



63
64
65
# File 'app/models/biological_association/dwc_extensions.rb', line 63

def dwc_relationship_of_resource_id
  biological_relationship.uris.first&.cached || biological_relationship_id
end

#dwc_relationship_remarksObject

TODO: Generic helper



134
135
136
# File 'app/models/biological_association/dwc_extensions.rb', line 134

def dwc_relationship_remarks
  Utilities::Strings.sanitize_for_csv( notes.collect{|n| n.text}.join(' | ')).presence
end

#dwc_resourceObject



54
55
56
57
58
59
60
61
# File 'app/models/biological_association/dwc_extensions.rb', line 54

def dwc_resource
  case biological_association_subject.class.base_class.name
  when 'Otu'
    ApplicationController.helpers.label_for_otu(biological_association_subject)
  when 'CollectionObject'
    ApplicationController.helpers.label_for_collection_object(biological_association_subject)
  end
end

#dwc_resource_idObject



45
46
47
48
49
50
51
52
# File 'app/models/biological_association/dwc_extensions.rb', line 45

def dwc_resource_id
  case biological_association_subject.class.base_class.name
  when 'Otu'
    biological_association_subject.uuid || biological_association_subject.uri || biological_association_subject.id
  when 'CollectionObject'
    biological_association_subject.dwc_occurrence_id
  end
end

#dwc_resource_relationship_idObject



41
42
43
# File 'app/models/biological_association/dwc_extensions.rb', line 41

def dwc_resource_relationship_id
  uuid || id
end

#globi_extension_jsonObject

Don’t use dwc_



27
28
29
30
31
32
33
34
35
# File 'app/models/biological_association/dwc_extensions.rb', line 27

def globi_extension_json
  r = {} 
   Export::Csv::Dwc::Extension::BiologicalAssociations::HEADERS.each do |h|
    if m = DWC_EXTENSION_MAP[h.to_sym]
      r[h] = send(m)
    end
  end
  r
end