Sha256: 7bb8a3c38ce83d8296178caadca925bb5979bb03322ba6e2ab0442fcb6fb976f

Contents?: true

Size: 759 Bytes

Versions: 1

Compression:

Stored size: 759 Bytes

Contents

module Memo
  class Option
    attr_reader :namespace, :is_all

    def initialize(args)
      @raw_args = args.to_a
      @is_all = args.include?("-a") ||
        args.include?("-all")

      case args
      in [*, "-n", namespace, *]
        @namespace = namespace
        @raw_args.delete("-n")
        @raw_args.delete(namespace)
      else
      end

      @args = @raw_args.select do |s|
        !s.start_with? "-"
      end
    end

    def [](index)
      @args[index]
    end

    def dir?
      include_any? "-dir", "-d"
    end

    def all?
      include_any? "-all", "-a"
    end

    def copy?
      include_any? "-copy", "-c"
    end

    private

    def include_any?(*args)
      args.map { |a| @raw_args.include?(a) }.any?
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ememo-0.1.6 lib/memo/cli/arg/option.rb