Module: GnCrossmap

Defined in:
lib/gn_crossmap.rb,
lib/gn_crossmap/stats.rb,
lib/gn_crossmap/reader.rb,
lib/gn_crossmap/writer.rb,
lib/gn_crossmap/version.rb,
lib/gn_crossmap/resolver.rb,
lib/gn_crossmap/collector.rb,
lib/gn_crossmap/resolver_job.rb,
lib/gn_crossmap/column_collector.rb,
lib/gn_crossmap/result_processor.rb,
lib/gn_crossmap/sci_name_collector.rb

Overview

rubocop:disable Metrics/ClassLength

Defined Under Namespace

Classes: Collector, ColumnCollector, Reader, Resolver, ResolverJob, ResultProcessor, SciNameCollector, Stats, Writer

Constant Summary collapse

INPUT_MODE =
"r:utf-8"
OUTPUT_MODE =
"w:utf-8"
MATCH_TYPES =
{
  0 => "No match",
  1 => "Exact string match",
  2 => "Canonical form exact match",
  3 => "Canonical form fuzzy match",
  4 => "Partial canonical form match",
  5 => "Partial canonical form fuzzy match",
  6 => "Genus part match",
  7 => "Error in matching"
}.freeze
VERSION =
"4.0.3"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.loggerObject

rubocop:enable all



57
58
59
# File 'lib/gn_crossmap.rb', line 57

def logger
  @logger ||= Logger.new(STDERR)
end

Class Method Details

.find_id(row, name) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/gn_crossmap.rb', line 65

def find_id(row, name)
  if row.key?(:taxonid) && row[:taxonid]
    row[:taxonid].to_s.strip
  else
    GnUUID.uuid(name.to_s)
  end
end

.log(message) ⇒ Object



61
62
63
# File 'lib/gn_crossmap.rb', line 61

def log(message)
  logger.info(message)
end

.opts_struct(opts) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/gn_crossmap.rb', line 73

def opts_struct(opts)
  resolver_url = "http://resolver.globalnames.org/name_resolvers.json"
  threads = opts[:threads].to_i
  opts[:threads] = threads.between?(1, 10) ? threads : 2
  with_classification = opts[:with_classification] ? true : false
  opts[:with_classification] = with_classification
  data_source_id = opts[:data_source_id].to_i
  opts[:data_source_id] = data_source_id.zero? ? 1 : data_source_id
  OpenStruct.new({ stats: Stats.new, alt_headers: [],
                   resolver_url: resolver_url }.merge(opts))
end

.run(opts) ⇒ Object

rubocop:disable Metrics/AbcSize



44
45
46
47
48
49
50
51
52
53
# File 'lib/gn_crossmap.rb', line 44

def run(opts)
  opts = opts_struct(opts)
  input_io, output_io = io(opts.input, opts.output)
  reader = create_reader(input_io, opts)
  data = block_given? ? reader.read(&Proc.new) : reader.read
  writer = create_writer(reader, output_io, opts)
  resolver = Resolver.new(writer, opts)
  block_given? ? resolver.resolve(data, &Proc.new) : resolver.resolve(data)
  resolver.stats
end

.versionObject



7
8
9
# File 'lib/gn_crossmap/version.rb', line 7

def self.version
  VERSION
end