Module: Export::CSV::Dwc::Extension::BiologicalAssociations

Defined in:
lib/export/csv/dwc/extension/biological_associations.rb

Overview

CSV for for a ResourceRelationship based extension

Constant Summary collapse

HEADERS_HASH =

See also BiologicalAssociation::DwcExtensions::DWC_EXTENSION_MAP, the two play off each other. Maintain this for order.

{
  # Required by dwca to link to core file, not part of the extension. This
  # determines the object on which this relationship will be displayed.
  coreid: '',
  resourceRelationshipID: 'http://rs.tdwg.org/dwc/terms/resourceRelationshipID',
  resourceID: 'http://rs.tdwg.org/dwc/terms/resourceID',
  'TW:Resource': Export::Dwca::LOCAL_RESOURCE_RELATIONSHIP_TERMS[:'TW:Resource'],
  relationshipOfResourceID: 'http://rs.tdwg.org/dwc/terms/relationshipOfResourceID',
  relationshipOfResource: 'http://rs.tdwg.org/dwc/terms/relationshipOfResource',
  relatedResourceID: 'http://rs.tdwg.org/dwc/terms/relatedResourceID',
  'TW:RelatedResource': Export::Dwca::LOCAL_RESOURCE_RELATIONSHIP_TERMS[:'TW:RelatedResource'],
  relationshipAccordingTo: 'http://rs.tdwg.org/dwc/terms/relationshipAccordingTo',
  relationshipEstablishedDate: 'http://rs.tdwg.org/dwc/terms/relationshipEstablishedDate',
  relationshipRemarks: 'http://rs.tdwg.org/dwc/terms/relationshipRemarks'
}.freeze
HEADERS =
HEADERS_HASH.keys.freeze
HEADERS_NAMESPACES =
HEADERS_HASH.values.freeze

Class Method Summary collapse

Class Method Details

.csv(scope, biological_association_relations_to_core) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/export/csv/dwc/extension/biological_associations.rb', line 27

def self.csv(scope, biological_association_relations_to_core)
  tbl = []
  tbl[0] = HEADERS

  scope.find_each do |b|
    # The resource relation only appears on the page of the core id with which
    # it is linked, so link to both where we can.
    if biological_association_relations_to_core[:subject].include?(b.id)
      tbl << b.darwin_core_extension_row(inverted: false)
    end
    if biological_association_relations_to_core[:object].include?(b.id)
      b.rotate = true
      tbl << b.darwin_core_extension_row(inverted: true)
    end
  end

  output = StringIO.new
  tbl.each do |row|
    output.puts ::CSV.generate_line(row, col_sep: "\t", encoding: Encoding::UTF_8)
  end

  output.string
end