Class: Tomo::CLI::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/tomo/cli/options.rb

Instance Method Summary collapse

Constructor Details

#initializeOptions

Returns a new instance of Options.



6
7
8
# File 'lib/tomo/cli/options.rb', line 6

def initialize
  @options = {}
end

Instance Method Details

#[](key) ⇒ Object



23
24
25
# File 'lib/tomo/cli/options.rb', line 23

def [](key)
  fetch(key, nil)
end

#[]=(key, value) ⇒ Object



27
28
29
# File 'lib/tomo/cli/options.rb', line 27

def []=(key, value)
  all(key).clear.push(value)
end

#all(key) ⇒ Object



31
32
33
# File 'lib/tomo/cli/options.rb', line 31

def all(key)
  options[key] ||= []
end

#any?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/tomo/cli/options.rb', line 10

def any?
  options.any?
end

#fetch(key, default) ⇒ Object



18
19
20
21
# File 'lib/tomo/cli/options.rb', line 18

def fetch(key, default)
  values = all(key)
  values.empty? ? default : values.first
end

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/tomo/cli/options.rb', line 14

def key?(key)
  !all(key).empty?
end