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



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'app/models/protonym/format.rb', line 143

def original_combination_full_name_hash_from_flat(row)
  data = {}
  gender = row['genus_gender']

  # ranks are symbols here, elsewhere strings.
  # loop protonyms
  finest_rank = nil
  ORIGINAL_COMBINATION_RANKS.each do |rank, type|
    next if row[rank].nil?

    finest_rank = rank

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

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

    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[finest_rank.to_s][1] = row[:name] # Ensure the last name is not genderized
  data
end

#original_combinations_flattenedObject

CAREFUL - the last name doesn’t get genderized in rendering !!! TODO: consider an ‘include_cached_misspelling’ Boolean to extend result to include ‘cached_misspelling`



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'app/models/protonym/format.rb', line 100

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}"

    # See unused original_combination_flat
    s.push "MAX(original_combination_protonyms_taxon_names.cached_gender) FILTER (WHERE taxon_name_relationships.type = '#{t}') AS #{rank}_gender"

    s.push "MAX(original_combination_protonyms_taxon_names.neuter_name) FILTER (WHERE taxon_name_relationships.type = '#{t}') AS #{rank}_neuter"
    s.push "MAX(original_combination_protonyms_taxon_names.masculine_name) FILTER (WHERE taxon_name_relationships.type  =  '#{t}') AS #{rank}_masculine"
    s.push "MAX(original_combination_protonyms_taxon_names.feminine_name) FILTER (WHERE taxon_name_relationships.type  = '#{t}') AS #{rank}_feminine"

    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.name, 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(:source, :original_combination_protonyms)
    .select(sel)
    .group('taxon_names.id, sources.id, citations.pages')
end