lib/domkey/view/option_selectable.rb in domkey-0.3.0 vs lib/domkey/view/option_selectable.rb in domkey-0.3.1

- old
+ new

@@ -2,30 +2,30 @@ module View module OptionSelectable # clears all options and sets only the desired value(s) # @param [String, Regexp] sets default designated option by String or Regexp - # @param [Array<String, Regexp>] sets each String, Regexp + # @param [Array<String, Regexp>] set more than one option by default strategy # @param [False] unselects all options # @param [Hash{how => value}] selects by how strategy where how is a symbol :label, :index, :text, :value # Clients need to implement individual strategy for each 'how' => 'value' pair based on what it means to be selected by what def set value before_set set_strategy value end - # @param [] opts. Represents a qualifier of what types of options to return. defaults to empty - # @return [Array<String>] when opts param emtpy returns array of default strings implemented by client - # @param [Symbol,Array<Symbol>] symbols represents what option selector to return - # @return [Array<Hash{what => value}] where what is a symbol for option selector, :index, :value, :text, :label + # @param opts [Symbol, Array<Symbol>] defaults to empty []. Represents a qualifier how to present selected options. + # @return [Array<String>] When opts param empty? array of default strings implemented by client as a presentation of options selected + # @param opts [Symbol,Array<Symbol>] ask for representation of options by 'what' + # @return [Array<Hash{what => value}] Whe opts is a list of symbols :index, :value, :text, :label corresponding to 'what' key 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 - # similar strategy to value but returns all options and not only selected ones + # @see +value+ returns all options and not only selected ones def options *opts opts = opts.flatten return options_by_default if opts.empty? options_by opts end @@ -53,48 +53,39 @@ end # strategy for selecting OptionSelectable object def set_strategy value case value - when String - set_by_string(value) - when Regexp - set_by_regexp(value) + when String, Regexp + set_by_value(value) when Array value.each { |v| set_strategy(v) } when Hash value.each_pair do |how, value| case how - when :label + when :label, :text set_by_label(value) - when :text - set_strategy(value) when :index set_by_index(value) when :value set_by_value(value) end end end end - def set_by_string value + # default strategy. set by value attribute + def set_by_value value fail Exception::NotImplementedError, "Subclass responsible for implementing" end - def set_by_regexp value - fail Exception::NotImplementedError, "Subclass responsible for implementing" - end - + # by visible text, label of the control def set_by_label value fail Exception::NotImplementedError, "Subclass responsible for implementing" end + # set by position in an index of options def set_by_index value - fail Exception::NotImplementedError, "Subclass responsible for implementing" - end - - def set_by_value value fail Exception::NotImplementedError, "Subclass responsible for implementing" end end end