Class: Cl::Opts::Validate::Validator

Inherits:
Struct
  • Object
show all
Includes:
Regex
Defined in:
lib/cl/opts/validate.rb

Direct Known Subclasses

Enum, Format, Range, Required, Requireds, Requires

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Regex

#format_regex

Instance Attribute Details

#cmdObject

Returns the value of attribute cmd

Returns:

  • (Object)

    the current value of cmd


14
15
16
# File 'lib/cl/opts/validate.rb', line 14

def cmd
  @cmd
end

#optsObject

Returns the value of attribute opts

Returns:

  • (Object)

    the current value of opts


14
15
16
# File 'lib/cl/opts/validate.rb', line 14

def opts
  @opts
end

#origObject

Returns the value of attribute orig

Returns:

  • (Object)

    the current value of orig


14
15
16
# File 'lib/cl/opts/validate.rb', line 14

def orig
  @orig
end

#valuesObject

Returns the value of attribute values

Returns:

  • (Object)

    the current value of values


14
15
16
# File 'lib/cl/opts/validate.rb', line 14

def values
  @values
end

Instance Method Details

#compact(hash, *keys) ⇒ Object


16
17
18
# File 'lib/cl/opts/validate.rb', line 16

def compact(hash, *keys)
  hash.reject { |_, value| value.nil? }.to_h
end

#invert(hash) ⇒ Object


20
21
22
# File 'lib/cl/opts/validate.rb', line 20

def invert(hash)
  hash.map { |key, obj| Array(obj).map { |obj| [obj, key] } }.flatten(1).to_h
end

#only(hash, *keys) ⇒ Object


24
25
26
# File 'lib/cl/opts/validate.rb', line 24

def only(hash, *keys)
  hash.select { |key, _| keys.include?(key) }.to_h
end