Module: Protonym::Format::ClassMethods

Defined in:
app/models/protonym/format.rb

Instance Method Summary collapse

Instance Method Details

#original_combination_full_name_hash_from_flat(row) ⇒ Hash

!! Does not include ‘[sic]’ !! Does not include ‘NOT SPECIFIED’ ranks.

Intent is to chain with scopes within COLDP export.

If this becomes more broadly useful consider optional ‘sic` inclusion

Returns:

  • (Hash)

    Similar pattern to full_name hash



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'app/models/protonym/format.rb', line 132

def original_combination_full_name_hash_from_flat(row)
  gender = nil
  data = {}

  # ranks are symbols here, elsewhere strings.
  # protonym loop
  ORIGINAL_COMBINATION_RANKS.each do |rank, type|
    if rank == :genus
      a = "#{rank}_gender".to_sym
      gender = row[a]
    end

    name_target = gender.nil? ? rank : (rank.to_s + '_' + gender).to_sym

    # TODO: add  verbatim to row
    name = row[name_target] || row[rank.to_s] || row[(rank.to_s + '_' + 'verbatim')]

    next if name.nil?

    v = [nil, name]

    unless ['genus', 'subgenus', 'species', 'subspecies'].include?(rank.to_s)
      v[0] = row[rank.to_s + ' ' + 'rank_class']
    end

    data[rank.to_s] = v
  end
  data
end

#original_combinations_flattenedObject

TODO: consider an ‘include_cached_misspelling’ Boolean to extend result to include ‘cached_misspelling`



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'app/models/protonym/format.rb', line 99

def original_combinations_flattened
  s = []
  abbreviation_cutoff = 'subspecies'
  abbreviate = false
  ::ORIGINAL_COMBINATION_RANKS.each do |rank, t|
    s.push "MAX(original_combination_protonyms_taxon_names.name) FILTER (WHERE taxon_name_relationships.type = '#{t}') AS #{rank}"

    if abbreviate
      s.push "MAX(original_combination_protonyms_taxon_names.rank_class) FILTER (WHERE taxon_name_relationships.type = '#{t}') AS #{rank}_rank_class"
    end

    abbreviate = true if rank == abbreviation_cutoff
  end

  s.push 'taxon_names.id, taxon_names.cached, taxon_names.cached_original_combination, taxon_names.cached_author_year, taxon_names.cached_nomenclature_date,
    taxon_names.rank_class, taxon_names.cached_misspelling, taxon_names.cached_is_valid, taxon_names.cached_valid_taxon_name_id, taxon_names.updated_by_id, taxon_names.updated_at, sources.id source_id, citations.pages'

  sel = s.join(',')

  Protonym.joins(:original_combination_protonyms, :source)
    .select(sel)
    .group('taxon_names.id, sources.id, citations.pages')
end