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

Class Method Summary collapse

Class Method Details

.area(common_name) ⇒ Object



23
24
25
# File 'lib/export/coldp/files/vernacular_name.rb', line 23

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

.generate(otus, reference_csv = nil) ⇒ Object



42
43
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
# File 'lib/export/coldp/files/vernacular_name.rb', line 42

def self.generate(otus, 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
    }

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

        csv << [
          o.id,
          n.name,
          transliteration(n),
          n.language&.alpha_3_bibliographic,
          n.geographic_area&.level0&.iso_3166_a2,
          area(n),
          sources.collect{|a| a.id}.join(',')  # reference_id
        ]

        Export::Coldp::Files::Reference.add_reference_rows(sources, reference_csv) 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)


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

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



28
29
30
# File 'lib/export/coldp/files/vernacular_name.rb', line 28

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



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

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