class TTY::Option::Params

Attributes

errors[R]

The parameter parsing errors

@api public

remaining[R]

The remaining unparsed arguments

@api public

Public Class Methods

create(parameters = {}, remaining = [], errors = []) click to toggle source
# File lib/tty/option/params.rb, line 12
def self.create(parameters = {}, remaining = [], errors = [])
  new(parameters, remaining: remaining, errors: errors)
end
new(parameters, remaining: [], errors: []) click to toggle source

Create Params

@api private

# File lib/tty/option/params.rb, line 33
def initialize(parameters, remaining: [], errors: [])
  @parameters = parameters
  @parameters.default_proc = ->(hash, key) do
    return hash[key] if hash.key?(key)

    case key
    when Symbol
      hash[key.to_s] if hash.key?(key.to_s)
    when String
      hash[key.to_sym] if hash.key?(key.to_sym)
    end
  end
  @remaining = remaining
  @errors = AggregateErrors.new(errors)
end

Public Instance Methods

==(other) click to toggle source
# File lib/tty/option/params.rb, line 88
def ==(other)
  return false unless other.kind_of?(TTY::Option::Params)

  @parameters == other.to_h
end
Also aliased as: eql?
[](key) click to toggle source

Access a given value for a key

@api public

# File lib/tty/option/params.rb, line 52
def [](key)
  @parameters[key]
end
[]=(key, value) click to toggle source

Assign value to a key

@api public

# File lib/tty/option/params.rb, line 59
def []=(key, value)
  @parameters[key] = value
end
eql?(other)
Alias for: ==
fetch(key, *args, &block) click to toggle source

Access a given value for a key

@api public

# File lib/tty/option/params.rb, line 66
def fetch(key, *args, &block)
  value = self[key]
  return value unless value.nil?

  @parameters.fetch(key, *args, &block)
end
hash() click to toggle source
# File lib/tty/option/params.rb, line 95
def hash
  @parameters.hash
end
inspect() click to toggle source

String representation of this params

@return [String]

@api public

# File lib/tty/option/params.rb, line 108
def inspect
  "#<#{self.class}#{to_h.inspect}>"
end
merge(other_params) click to toggle source
# File lib/tty/option/params.rb, line 73
def merge(other_params)
  @parameters.merge(other_params)
end
merge!(other_params) click to toggle source
# File lib/tty/option/params.rb, line 77
def merge!(other_params)
  @parameters.merge!(other_params)
end
to_h() click to toggle source
# File lib/tty/option/params.rb, line 99
def to_h
  @parameters.to_h
end
to_s() click to toggle source

String representation of the parameters

@return [String]

@api public

# File lib/tty/option/params.rb, line 117
def to_s
  to_h.to_s
end
valid?() click to toggle source

Check if params have any errors

@api public

# File lib/tty/option/params.rb, line 84
def valid?
  @errors.empty?
end