Sha256: a4eef8a83babb37ee210dc5361471c2eea4270b8f150029f6baa7dfd03130f7b

Contents?: true

Size: 1.84 KB

Versions: 18

Compression:

Stored size: 1.84 KB

Contents

# frozen_string_literal: true

# Copyright (c) 2018 Yegor Bugayenko
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the 'Software'), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

require 'slop'
require_relative '../log'
require_relative '../score'

# NEXT command.
# Author:: Yegor Bugayenko (yegor256@gmail.com)
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
# License:: MIT
module Zold
  # Calculate next score
  class Next
    def initialize(log: Log::Quiet.new)
      @log = log
    end

    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 '--help', 'Print instructions'
      end
      if opts.help?
        @log.info(opts.to_s)
        return
      end
      calculate(opts)
    end

    private

    def calculate(opts)
      @log.info(Score.parse(opts.arguments[1]).next.to_s)
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
zold-0.14.35 lib/zold/commands/next.rb
zold-0.14.34 lib/zold/commands/next.rb
zold-0.14.33 lib/zold/commands/next.rb
zold-0.14.32 lib/zold/commands/next.rb
zold-0.14.31 lib/zold/commands/next.rb
zold-0.14.30 lib/zold/commands/next.rb
zold-0.14.29 lib/zold/commands/next.rb
zold-0.14.28 lib/zold/commands/next.rb
zold-0.14.27 lib/zold/commands/next.rb
zold-0.14.26 lib/zold/commands/next.rb
zold-0.14.25 lib/zold/commands/next.rb
zold-0.14.24 lib/zold/commands/next.rb
zold-0.14.23 lib/zold/commands/next.rb
zold-0.14.22 lib/zold/commands/next.rb
zold-0.14.21 lib/zold/commands/next.rb
zold-0.14.20 lib/zold/commands/next.rb
zold-0.14.19 lib/zold/commands/next.rb
zold-0.14.18 lib/zold/commands/next.rb