Module: GnListResolver

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

Overview

Namespace module for resolving lists with GN sources

Defined Under Namespace

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

Constant Summary collapse

VERSION =
"3.3.1.0"
INPUT_MODE =
"r:utf-8"
OUTPUT_MODE =
"w:utf-8"
MATCH_TYPE_EMPTY =
:EmptyMatch
RESOLVER_URL =
ENV["GN_RESOLVER_URL"] ||
"http://index-api.globalnames.org/api/graphql"
MATCH_TYPES =
{
  EmptyMatch: "No match",
  ExactNameMatchByUUID: "Exact string match",
  ExactCanonicalNameMatchByUUID: "Canonical form exact match",
  FuzzyCanonicalMatch: "Canonical form fuzzy match",
  ExactPartialMatch: "Partial canonical form match",
  FuzzyPartialMatch: "Partial canonical form fuzzy match",
  ExactMatchPartialByGenus: "Genus part match",
  ErrorInMatch: "Error in matching"
}.freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.loggerObject

rubocop:enable all



50
51
52
# File 'lib/gn_list_resolver.rb', line 50

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

Class Method Details

.find_id(row, name) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/gn_list_resolver.rb', line 58

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



54
55
56
# File 'lib/gn_list_resolver.rb', line 54

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

.opts_struct(opts) ⇒ Object



66
67
68
69
70
71
72
73
74
# File 'lib/gn_list_resolver.rb', line 66

def opts_struct(opts)
  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: [] }.merge(opts))
end

.run(opts) ⇒ Object

rubocop:disable Metrics/AbcSize



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/gn_list_resolver.rb', line 36

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)
  logger.warn(resolver.stats.stats.pretty_inspect) if opts[:debug]
  resolver.stats
end

.versionObject



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

def self.version
  VERSION
end