Module: BiologicalAssociation::DwcExtensions
- Extended by:
- ActiveSupport::Concern
- Included in:
- BiologicalAssociation
- Defined in:
- app/models/biological_association/dwc_extensions.rb
Instance Method Summary collapse
- #darwin_core_extension_json(inverted = false) ⇒ Object
-
#darwin_core_extension_row(inverted: false) ⇒ Object
Don’t use dwc_ !! inverted means subject and object have already been switched, but relationship must use ‘inverted_name` instead of `name`.
- #dwc_related_resource(inverted = false) ⇒ Object
- #dwc_related_resource_id(inverted = false) ⇒ Object
-
#dwc_relationship_according_to(inverted = false) ⇒ Object
TODO: Should reference DOIs, Identifiers, or identifiers in lieu of short citations.
- #dwc_relationship_established_date(inverted = false) ⇒ Object
- #dwc_relationship_of_resource(inverted = false) ⇒ Object
- #dwc_relationship_of_resource_id(inverted = false) ⇒ Object
-
#dwc_relationship_remarks(inverted = false) ⇒ Object
TODO: Generic helper.
- #dwc_resource(inverted = false) ⇒ Object
- #dwc_resource_id(inverted = false) ⇒ Object
- #dwc_resource_relationship_coreid(inverted = false) ⇒ Object
- #dwc_resource_relationship_id(inverted = false) ⇒ Object
-
#globi_extension_json ⇒ Object
Don’t use dwc_.
Instance Method Details
#darwin_core_extension_json(inverted = false) ⇒ Object
46 47 48 |
# File 'app/models/biological_association/dwc_extensions.rb', line 46 def darwin_core_extension_json(inverted = false) end |
#darwin_core_extension_row(inverted: false) ⇒ Object
Don’t use dwc_ !! inverted means subject and object have already been switched, but relationship must use ‘inverted_name` instead of `name`.
25 26 27 |
# File 'app/models/biological_association/dwc_extensions.rb', line 25 def darwin_core_extension_row(inverted: false) Export::CSV::Dwc::Extension::BiologicalAssociations::HEADERS.collect{|h| send(DWC_EXTENSION_MAP[h.to_sym], inverted)} end |
#dwc_related_resource(inverted = false) ⇒ Object
96 97 98 99 100 101 102 103 |
# File 'app/models/biological_association/dwc_extensions.rb', line 96 def (inverted = false) 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 |
#dwc_related_resource_id(inverted = false) ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'app/models/biological_association/dwc_extensions.rb', line 87 def (inverted = false) 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_to(inverted = false) ⇒ Object
TODO: Should reference DOIs, Identifiers, or identifiers in lieu of short citations
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'app/models/biological_association/dwc_extensions.rb', line 106 def dwc_relationship_according_to(inverted = false) 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_date(inverted = false) ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'app/models/biological_association/dwc_extensions.rb', line 130 def dwc_relationship_established_date(inverted = false) 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_resource(inverted = false) ⇒ Object
79 80 81 82 83 84 85 |
# File 'app/models/biological_association/dwc_extensions.rb', line 79 def dwc_relationship_of_resource(inverted = false) if inverted biological_relationship.inverted_name else biological_relationship.name end end |
#dwc_relationship_of_resource_id(inverted = false) ⇒ Object
72 73 74 75 76 77 |
# File 'app/models/biological_association/dwc_extensions.rb', line 72 def dwc_relationship_of_resource_id(inverted = false) s = biological_relationship.uris.first&.cached || biological_relationship_id # TODO: this might mess up uri handling inverted ? "#{s} inverted" : s end |
#dwc_relationship_remarks(inverted = false) ⇒ Object
TODO: Generic helper
150 151 152 |
# File 'app/models/biological_association/dwc_extensions.rb', line 150 def dwc_relationship_remarks(inverted = false) Utilities::Strings.sanitize_for_csv( notes.collect{|n| n.text}.join(' | ')).presence end |
#dwc_resource(inverted = false) ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'app/models/biological_association/dwc_extensions.rb', line 63 def dwc_resource(inverted = false) 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_id(inverted = false) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'app/models/biological_association/dwc_extensions.rb', line 54 def dwc_resource_id(inverted = false) 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_coreid(inverted = false) ⇒ Object
40 41 42 43 44 |
# File 'app/models/biological_association/dwc_extensions.rb', line 40 def dwc_resource_relationship_coreid(inverted = false) # Note that this could be subject or object of the original association (see # note above on `inverted`), which is what we want. dwc_resource_id(inverted) end |
#dwc_resource_relationship_id(inverted = false) ⇒ Object
50 51 52 |
# File 'app/models/biological_association/dwc_extensions.rb', line 50 def dwc_resource_relationship_id(inverted = false) uuid || id end |
#globi_extension_json ⇒ Object
Don’t use dwc_
30 31 32 33 34 35 36 37 38 |
# File 'app/models/biological_association/dwc_extensions.rb', line 30 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, false) end end r end |