Class: GnCrossmap::ColumnCollector

Inherits:
Object
  • Object
show all
Defined in:
lib/gn_crossmap/column_collector.rb

Overview

Assemble data from CSV reader by checking column fields

Constant Summary collapse

RANKS =
%i[kingdom subkingdom phylum subphylum superclass class
subclass cohort superorder order suborder infraorder superfamily
family subfamily tribe subtribe genus subgenus section species
subspecies variety form].freeze
SPECIES_RANKS =
%i[genus species subspecies variety form].freeze

Instance Method Summary collapse

Constructor Details

#initialize(fields) ⇒ ColumnCollector

Returns a new instance of ColumnCollector.

Raises:



12
13
14
15
16
17
# File 'lib/gn_crossmap/column_collector.rb', line 12

def initialize(fields)
  @fields = fields
  err = "At least some of these fields must exist in " \
    "the CSV header: '#{RANKS.join('\', \'')}'"
  raise GnCrossmapError, err if (RANKS - @fields).size == RANKS.size
end

Instance Method Details

#id_name_rank(row) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/gn_crossmap/column_collector.rb', line 19

def id_name_rank(row)
  @row = row
  rank = find_rank
  return nil unless rank
  name = assemble_name(rank)
  return nil unless name
  id = GnCrossmap.find_id(@row, name)
  return nil if id.strip.to_s == ""
  { id: id, name: name, rank: rank.to_s }
end