Module: Domkey::View::OptionSelectable

Included in:
OptionSelectableGroup, SelectList
Defined in:
lib/domkey/view/option_selectable.rb

Instance Method Summary collapse

Instance Method Details

#options(*opts) ⇒ Object

See Also:

  • returns all options and not only selected ones


27
28
29
30
31
# File 'lib/domkey/view/option_selectable.rb', line 27

def options *opts
  opts = opts.flatten
  return options_by_default if opts.empty?
  options_by opts
end

#set(value) ⇒ Object

clears all options and sets only the desired value(s) Clients need to implement individual strategy for each ‘how’ => ‘value’ pair based on what it means to be selected by what

Parameters:

  • sets (String, Regexp)

    default designated option by String or Regexp

  • set (Array<String, Regexp>)

    more than one option by default strategy

  • unselects (False)

    all options

  • selects (Hash{how => value})

    by how strategy where how is a symbol :label, :index, :text, :value



11
12
13
14
# File 'lib/domkey/view/option_selectable.rb', line 11

def set value
  before_set
  set_strategy value
end

#value(*opts) ⇒ Array<String>, ...

Parameters:

  • opts (Symbol, Array<Symbol>)

    defaults to empty []. Represents a qualifier how to present selected options.

  • opts (Symbol, Array<Symbol>)

    ask for representation of options by ‘what’

Returns:

  • (Array<String>)

    When opts param empty? array of default strings implemented by client as a presentation of options selected

  • (Array<Hash{what => value}] Whe opts is a list of symbols :index, :value, :text, :label corresponding to 'what' key)

    Array<Hash=> value] Whe opts is a list of symbols :index, :value, :text, :label corresponding to ‘what’ key



20
21
22
23
24
# File 'lib/domkey/view/option_selectable.rb', line 20

def value *opts
  opts = opts.flatten
  return value_by_default if (opts.empty? || opts.find { |e| e.kind_of?(String) })
  value_by_options opts
end