Class: Unipept::Commands::Taxa2Tree

Inherits:
ApiRunner show all
Defined in:
lib/commands/unipept/taxa2tree.rb

Instance Attribute Summary

Attributes inherited from ApiRunner

#configuration, #url, #user_agent

Instance Method Summary collapse

Methods inherited from ApiRunner

#batch_iterator, #concurrent_requests, #default_batch_size, #formatter, #host, #output_writer, #queue_size, #run, #save_error, #selected_fields

Constructor Details

#initialize(args, opts, cmd) ⇒ Taxa2Tree

Returns a new instance of Taxa2Tree.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/commands/unipept/taxa2tree.rb', line 4

def initialize(args, opts, cmd)
  super

  # JSON is the default format for this command
  args[:format] = 'json' unless args[:format]

  unless %w[url html json].include? args[:format]
    warn "Format #{args[:format]} is not supported by taxa2tree. Use html, url or json (default)."
    exit 1
  end

  if options[:format] == 'html'
    # Overwrite the URL for this command, since it's possible that it uses HTML generated by the server.
    @url = "#{@host}/api/v2/#{cmd.name}.html"
  elsif args[:format] == 'url'
    @link = true
  end
end

Instance Method Details

#batch_sizeObject



27
28
29
30
31
32
33
# File 'lib/commands/unipept/taxa2tree.rb', line 27

def batch_size
  return arguments.length unless arguments.empty?
  return File.foreach(options[:input]).inject(0) { |c, _| c + 1 } if options[:input]

  @stdin_contents = $stdin.readlines
  @stdin_contents.length
end

#input_iteratorObject



35
36
37
38
39
40
# File 'lib/commands/unipept/taxa2tree.rb', line 35

def input_iterator
  return arguments.each unless arguments.empty?
  return File.foreach(options[:input]) if options[:input]

  @stdin_contents.each
end

#required_fieldsObject



23
24
25
# File 'lib/commands/unipept/taxa2tree.rb', line 23

def required_fields
  ['taxon_id']
end