Module: Export::Coldp::Files::VernacularName

Defined in:
lib/export/coldp/files/vernacular_name.rb

Overview

taxon_id name - ORIGINAL LANGUAGE transliteration language country area sex reference_id modified modifiedBy

Class Method Summary collapse

Class Method Details

.area(common_name) ⇒ Object



25
26
27
# File 'lib/export/coldp/files/vernacular_name.rb', line 25

def self.area(common_name)
  common_name.geographic_area&.self_and_ancestors&.collect{|a| a.name}&.join('; ')
end

.generate(otus, project_members, reference_csv = nil) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/export/coldp/files/vernacular_name.rb', line 44

def self.generate(otus, project_members, reference_csv = nil )
  CSV.generate(col_sep: "\t") do |csv|

    # TODO: Biocuration attributes on these two
    # sex

    csv << %w{
      taxonID
      name
      transliteration
      language
      country
      area
      referenceID
      modified
      modifiedBy
    }

    otus.joins(:common_names).each do |o|
      o.common_names.each do |n|
        sources = n.sources.load

        csv << [
          o.id,                                                          # taxon_id
          n.name,                                                        # name
          transliteration(n),                                            # transliteration
          n.language&.alpha_3_bibliographic,                             # language
          n.geographic_area&.level0&.iso_3166_a2,                        # country
          area(n),                                                       # area
          sources.collect{|a| a.id}.join(','),                           # reference_id
          Export::Coldp.modified(n[:updated_at]),                        # modified
          Export::Coldp.modified_by(n[:updated_by_id], project_members)  # modified_by
        ]

        Export::Coldp::Files::Reference.add_reference_rows(sources, reference_csv, project_members) if reference_csv && sources.any?
      end
    end
  end
end

.reference_id(common_name) ⇒ String?

“supporting the taxonomic concept” Potentially- all other Citations tied to OTU, what exactly supports a concept?

Not used internally within CoLDP, for reference only. TODO: confirm.

Returns:

  • (String, nil)


38
39
40
41
42
# File 'lib/export/coldp/files/vernacular_name.rb', line 38

def self.reference_id(common_name)
  i = common_name.sources.pluck(:id)
  return i.join(',') if i.any?
  nil
end

.sex(common_name) ⇒ Object

TODO: Map to biocuration attribute via URI



30
31
32
# File 'lib/export/coldp/files/vernacular_name.rb', line 30

def self.sex(common_name)
  nil
end

.transliteration(common_name) ⇒ String?

Returns the ‘English’ translation(s) if available.

Returns:

  • (String, nil)

    the ‘English’ translation(s) if available



16
17
18
19
20
21
22
23
# File 'lib/export/coldp/files/vernacular_name.rb', line 16

def self.transliteration(common_name)
  n = common_name.alternate_values.where(type: 'AlternateValue::Translation', alternate_value_object_attribute: :name).load
  if n.any?
    n.collect{|a| a.language.name == 'English' ? a.language.name : nil}.compact.join('; ')
  else
    nil
  end
end