Sha256: d9cb3d698ef3826def07702d3f661be0790d209c87870767cf6e968549a579c4

Contents?: true

Size: 744 Bytes

Versions: 13

Compression:

Stored size: 744 Bytes

Contents

require 'cl/cast'

class Cl
  class Arg < Struct.new(:name, :opts)
    include Cast

    def define(const)
      const.send(:attr_accessor, name)
    end

    def set(cmd, value)
      cmd.send(:"#{name}=", cast(value))
    end

    def type
      opts[:type] || :string
    end

    def description
      opts[:description]
    end

    def splat?
      type == :array
    end

    def required?
      !!opts[:required]
    end

    def to_s
      str = name
      case type
      when :array          then str = "#{str}.."
      when :integer, :int  then str = "#{str}:int"
      when :boolean, :bool then str = "#{str}:bool"
      when :float          then str = "#{str}:float"
      end
      required? ? str : "[#{str}]"
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
cl-0.1.12 lib/cl/arg.rb
cl-0.1.11 lib/cl/arg.rb
cl-0.1.10 lib/cl/arg.rb
cl-0.1.9 lib/cl/arg.rb
cl-0.1.8 lib/cl/arg.rb
cl-0.1.7 lib/cl/arg.rb
cl-0.1.6 lib/cl/arg.rb
cl-0.1.5 lib/cl/arg.rb
cl-0.1.4 lib/cl/arg.rb
cl-0.1.3 lib/cl/arg.rb
cl-0.1.2 lib/cl/arg.rb
cl-0.1.1 lib/cl/arg.rb
cl-0.1.0 lib/cl/arg.rb