Class: Match::Otu::MorphospeciesName

Inherits:
Object
  • Object
show all
Includes:
NameBatchMatcher
Defined in:
lib/match/otu/morphospecies_name.rb

Constant Summary

Constants included from NameBatchMatcher

NameBatchMatcher::MAX_NAMES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from NameBatchMatcher

#call

Constructor Details

#initialize(names:, project_id:, taxon_name_id: nil) ⇒ MorphospeciesName

Returns a new instance of MorphospeciesName.

Parameters:

  • names (Array<String>)

    array of name strings to match

  • project_id (Integer)
  • taxon_name_id (Integer, nil) (defaults to: nil)

    scope matches to descendants of this TaxonName



36
37
38
39
40
# File 'lib/match/otu/morphospecies_name.rb', line 36

def initialize(names:, project_id:, taxon_name_id: nil)
  @names = names.first(NameBatchMatcher::MAX_NAMES)
  @project_id = project_id
  @taxon_name_id = taxon_name_id
end

Instance Attribute Details

#namesObject (readonly)

Returns the value of attribute names.



31
32
33
# File 'lib/match/otu/morphospecies_name.rb', line 31

def names
  @names
end

#project_idObject (readonly)

Returns the value of attribute project_id.



31
32
33
# File 'lib/match/otu/morphospecies_name.rb', line 31

def project_id
  @project_id
end

#taxon_name_idObject (readonly)

Returns the value of attribute taxon_name_id.



31
32
33
# File 'lib/match/otu/morphospecies_name.rb', line 31

def taxon_name_id
  @taxon_name_id
end

Instance Method Details

#match_name(name) ⇒ Hash (private)

Parameters:

  • name (String)

Returns:

  • (Hash)


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/match/otu/morphospecies_name.rb', line 46

def match_name(name)
  genus_term, otu_term = ::Otu.split_morphospecies_name(name)
  return no_match unless genus_term

  otus = ::Queries::Otu::Filter.new(
    genus_name: genus_term,
    name: otu_term,
    name_exact: true,
    taxon_name_id:,
    descendants: taxon_name_id.present?,
    project_id:
  ).all.eager_load(:taxon_name).to_a

  return no_match if otus.empty?

  {
    taxon_name_id: otus.first.taxon_name_id,
    taxon_name: otus.first.taxon_name,
    otus:,
    ambiguous: otus.map(&:taxon_name_id).uniq.size > 1, # homonym genera, or stray duplicate Otu rows
    matched: true
  }
end

#no_matchHash (private)

Returns:

  • (Hash)


71
72
73
# File 'lib/match/otu/morphospecies_name.rb', line 71

def no_match
  { taxon_name_id: nil, taxon_name: nil, otus: [], ambiguous: false, matched: false }
end