Module: Vendor::Colrapi

Defined in:
lib/vendor/colrapi.rb

Overview

A middle-layer wrapper between Colrapi and TaxonWorks

Constant Summary collapse

DATASETS =
{
    col: '3LR'
}.freeze

Class Method Summary collapse

Class Method Details

.align_classification(taxonworks_object, colrapi_result) ⇒ Array

2 row alignment facilitator

Returns:

  • (Array)

    with hashes {

    { rank: 'species'
      col: 'name',
      taxonworks: 'name'
      rank_origin: :col, :taxonworks, :both
    }
    


26
27
28
# File 'lib/vendor/colrapi.rb', line 26

def self.align_classification(taxonworks_object, colrapi_result)
  r = []
end

.collection_object_scientific_name(collection_object) ⇒ Object

Extend to buffered with GNA in middle layer? Text only, taxon name cached or OTU name for the most recent determination



88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/vendor/colrapi.rb', line 88

def self.collection_object_scientific_name(collection_object)
  return nil if collection_object.nil?
  if a = collection_object.taxon_determinations.order(:position)&.first
    if a.otu.taxon_name
      a.otu.taxon_name.cached
    else
      a.otu.name
    end
  else
    nil
  end
end

.name_status(taxonworks_object, colrapi_result) ⇒ Object

},

    accepted: {}
   }
  ]
}

Returns:

  • hash { taxonworks_name: name }

    col_results: [
        { usage: {
           name:
           status:
    


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/vendor/colrapi.rb', line 45

def self.name_status(taxonworks_object, colrapi_result)
  o = taxonworks_object

  r = {
      taxonworks_name: collection_object_scientific_name(o),
      col_usages: [],
      provisional_status: :accepted,
  }

  if colrapi_result.dig('total') == 0
    r[:provisional_status] = :undeterminable
    return r
  end

  colrapi_result['result'].each do |u|
    i = u['usage']

    d = {
      usage: {},
      accepted: {}
    }

    d[:usage][:name] = i.dig *%w{name scientificName}
    d[:usage][:status] = i['status']

    if i['accepted']
      d[:accepted][:name] = i.dig *%w{accepted name scientificName}
      d[:accepted][:status] = i.dig *%w{accepted status}
    end

    if d[:usage][:status] == 'synonym' && (d[:usage][:name] == r[:taxonworks_name])
      r[:provisional_status] = :synonym
    end

    r[:col_usages].push d
  end
  r
end