Module: Clue::Options
- Included in:
- Clue
- Defined in:
- lib/clue/options.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#singular_options ⇒ Object
readonly
Returns the value of attribute singular_options.
Instance Method Summary collapse
-
#add_option(key, value) ⇒ Object
Add a single options.
-
#add_options(opts = {}) ⇒ Object
Add many options.
-
#add_singular_option(option) ⇒ Object
Add a singular option.
-
#add_singular_options(options) ⇒ Object
Add many singular options.
-
#cli_options ⇒ Object
Returns the options string.
-
#init_options(options = nil) ⇒ Object
Initialize options ivars.
-
#options_as_array ⇒ Object
Returns options as an array.
-
#parse_options(options) ⇒ Object
Separate simple options from valued ones.
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/clue/options.rb', line 4 def @options end |
#singular_options ⇒ Object (readonly)
Returns the value of attribute singular_options.
4 5 6 |
# File 'lib/clue/options.rb', line 4 def @singular_options end |
Instance Method Details
#add_option(key, value) ⇒ Object
Add a single options
42 43 44 |
# File 'lib/clue/options.rb', line 42 def add_option(key, value) @options[key.to_sym] = value.to_s end |
#add_options(opts = {}) ⇒ Object
Add many options
47 48 49 |
# File 'lib/clue/options.rb', line 47 def (opts = {}) opts.each { |key, value| add_option key, value } end |
#add_singular_option(option) ⇒ Object
Add a singular option
27 28 29 30 |
# File 'lib/clue/options.rb', line 27 def add_singular_option(option) @singular_options << option.to_s @singular_options.uniq! end |
#add_singular_options(options) ⇒ Object
Add many singular options
33 34 35 36 37 38 39 |
# File 'lib/clue/options.rb', line 33 def () return unless = .split(' ') if .is_a?(String) @singular_options += .map(&:to_s) @singular_options.uniq! end |
#cli_options ⇒ Object
Returns the options string
52 53 54 |
# File 'lib/clue/options.rb', line 52 def .join self.config[:between_options] end |
#init_options(options = nil) ⇒ Object
Initialize options ivars
7 8 9 10 11 12 |
# File 'lib/clue/options.rb', line 7 def ( = nil) @options = {} @singular_options = [] () if end |
#options_as_array ⇒ Object
Returns options as an array
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/clue/options.rb', line 57 def # Valued options ary = @options.each_with_object([]) do |(key, value), memo| prefix = self.config[:option_prefix] separator = self.config[:option_value_separator] delimiter = self.config[:option_delimiter] memo << "#{prefix}#{key.to_s}#{separator}#{delimiter}#{value.to_s}#{delimiter}" end # Singular options ary = @singular_options.each_with_object(ary) do |opt, memo| prefix = self.config[:option_prefix] memo << "#{prefix}#{opt.to_s}" end ary end |
#parse_options(options) ⇒ Object
Separate simple options from valued ones.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/clue/options.rb', line 15 def () if .kind_of?(Hash) @options = elsif .kind_of?(Array) @singular_options = @options = @singular_options.pop if @singular_options.last.kind_of?(Hash) elsif .kind_of?(String) || .kind_of?(Symbol) @singular_options = [.to_sym] end end |