class MiGA::Cli::Action::Stats

Public Instance Methods

parse_cli() click to toggle source
# File lib/miga/cli/action/stats.rb, line 8
def parse_cli
  cli.defaults = {try_load: false}
  cli.parse do |opt|
    cli.opt_object(opt, [:project, :dataset_opt, :result])
    opt.on(
      '--key STRING',
      'Return only the value of the requested key'
      ){ |v| cli[:key] = v }
    opt.on(
      '--compute-and-save',
      'Compute and saves the statistics'
      ){ |v| cli[:compute] = v }
    opt.on(
      '--try-load',
      'Check if stat exists instead of computing on --compute-and-save'
      ){ |v| cli[:try_load] = v }
  end
end
perform() click to toggle source
# File lib/miga/cli/action/stats.rb, line 27
def perform
  cli[:compute] = false if cli[:try_load] and
    (not r[:stats].nil?) and (not r[:stats].empty?)
  r = cli.load_result
  if cli[:compute]
    cli.say 'Computing statistics'
    method = :"compute_#{cli[:result]}"
    stats = self.respond_to?(method, true) ? send(method, r) : nil
    unless stats.nil?
      r[:stats] = stats
      r.save
    end
  end
  if cli[:key].nil?
    r[:stats].each do |k,v|
      cli.puts "#{k==:g_c_content ? 'G+C content' : k.to_s.unmiga_name.capitalize}: #{
        v.is_a?(Array) ? v.join(' ') : v}."
    end
  else
    v = r[:stats][cli[:key].downcase.miga_name.to_sym]
    puts v.is_a?(Array) ? v.first : v
  end
end