Class: Voom::Parameters

Inherits:
Object
  • Object
show all
Defined in:
lib/voom/parameters.rb

Overview

Provides a query interface for the ruby parameters method

Instance Method Summary collapse

Constructor Details

#initialize(parameters) ⇒ Parameters

Returns a new instance of Parameters.



4
5
6
# File 'lib/voom/parameters.rb', line 4

def initialize(parameters)
  @params = parameters
end

Instance Method Details

#argsObject



8
9
10
# File 'lib/voom/parameters.rb', line 8

def args
  @params.select {|p| p.first == :req || p.first == :opt}
end

#names(args_or_options) ⇒ Object



69
70
71
# File 'lib/voom/parameters.rb', line 69

def names(args_or_options)
  args_or_options.map(&:last)
end

#optional_argsObject



20
21
22
# File 'lib/voom/parameters.rb', line 20

def optional_args
  @params.select {|p| p.first == :opt}
end

#optional_args?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/voom/parameters.rb', line 24

def optional_args?
      optional_args.any?
end

#optional_optionsObject



53
54
55
# File 'lib/voom/parameters.rb', line 53

def optional_options
  @params.select {|p| p.first == :key}
end

#optional_options?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/voom/parameters.rb', line 57

def optional_options?
  optional_options.any?
end

#optionsObject



36
37
38
# File 'lib/voom/parameters.rb', line 36

def options
  @params.select {|p| p.first == :keyreq || p.first == :key}
end

#options?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/voom/parameters.rb', line 40

def options?
  options.any?
end

#required_argsObject



12
13
14
# File 'lib/voom/parameters.rb', line 12

def required_args
  @params.select {|p| p.first == :req}
end

#required_args?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/voom/parameters.rb', line 16

def required_args?
  required_args.any?
end

#required_optionsObject



44
45
46
# File 'lib/voom/parameters.rb', line 44

def required_options
  @params.select {|p| p.first == :keyreq}
end

#required_options?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/voom/parameters.rb', line 48

def required_options?
  required_options.any?
end

#spalts_optionsObject



61
62
63
# File 'lib/voom/parameters.rb', line 61

def spalts_options
  @params.select {|p| p.first == :keyrest}
end

#splats_argsObject



28
29
30
# File 'lib/voom/parameters.rb', line 28

def splats_args
  @params.select {|p| p.first == :rest}
end

#splats_args?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/voom/parameters.rb', line 32

def splats_args?
  splats_args.any?
end

#splats_options?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/voom/parameters.rb', line 65

def splats_options?
  spalts_options.any?
end