module GnCrossmap
Namespace module for crossmapping checklists wth GN sources
rubocop:disable Metrics/ClassLength
Namespace module for crossmapping checklists to GN sources
Constants
- INPUT_MODE
- MATCH_TYPES
- OUTPUT_MODE
- VERSION
Attributes
logger[W]
Public Class Methods
find_id(row, name)
click to toggle source
# 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)
click to toggle source
# File lib/gn_crossmap.rb, line 61 def log(message) logger.info(message) end
logger()
click to toggle source
rubocop:enable all
# File lib/gn_crossmap.rb, line 57 def logger @logger ||= Logger.new(STDERR) end
opts_struct(opts)
click to toggle source
# 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)
click to toggle source
rubocop:disable Metrics/AbcSize
# 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
version()
click to toggle source
# File lib/gn_crossmap/version.rb, line 7 def self.version VERSION end
Private Class Methods
create_reader(input_io, opts)
click to toggle source
# File lib/gn_crossmap.rb, line 92 def create_reader(input_io, opts) Reader.new(input_io, input_name(opts.input), opts.skip_original, opts.alt_headers, opts.stats) end
create_writer(reader, output_io, opts)
click to toggle source
# File lib/gn_crossmap.rb, line 87 def create_writer(reader, output_io, opts) Writer.new(output_io, reader.original_fields, output_name(opts.output), opts.with_classification) end
input_name(input)
click to toggle source
# File lib/gn_crossmap.rb, line 120 def input_name(input) input.nil? || input == "-" ? "STDIN" : input end
io(input, output)
click to toggle source
# File lib/gn_crossmap.rb, line 97 def io(input, output) io_in = iogen(input, INPUT_MODE) io_out = iogen(output, OUTPUT_MODE) [io_in, io_out] end
iogen(arg, mode)
click to toggle source
# File lib/gn_crossmap.rb, line 103 def iogen(arg, mode) if arg.nil? || arg == "-" mode == INPUT_MODE ? stdin : STDOUT else fd_i = IO.sysopen(arg, mode) IO.new(fd_i, mode) end end
output_name(output)
click to toggle source
# File lib/gn_crossmap.rb, line 124 def output_name(output) output.nil? || output == "-" ? "STDOUT" : output end
stdin()
click to toggle source
# File lib/gn_crossmap.rb, line 112 def stdin temp = Tempfile.open("stdin") return STDIN if File.file?(STDIN) IO.copy_stream(STDIN, temp) fd_i = IO.sysopen(temp, INPUT_MODE) IO.new(fd_i, INPUT_MODE) end