class Zold::Next

Calculate next score

Public Class Methods

new(log: Log::NULL) click to toggle source
# File lib/zold/commands/next.rb, line 37
def initialize(log: Log::NULL)
  @log = log
end

Public Instance Methods

run(args = []) click to toggle source
# File lib/zold/commands/next.rb, line 41
    def run(args = [])
      opts = Slop.parse(args, help: true, suppress_errors: true) do |o|
        o.banner = "Usage: zold next [options] score
Available options:"
        o.bool '--low-priority',
          'Set the lowest priority to this process',
          default: false
        o.bool '--help', 'Print instructions'
      end
      if opts.help?
        @log.info(opts.to_s)
        return
      end
      calculate(opts)
    end

Private Instance Methods

calculate(opts) click to toggle source
# File lib/zold/commands/next.rb, line 59
def calculate(opts)
  Process.setpriority(Process::PRIO_PROCESS, 0, 20) if opts['low-priority']
  @log.info(Score.parse(opts.arguments.drop_while { |a| a.start_with?('--') }[1]).next.to_s)
end