lib/domkey/view/labeled_group.rb in domkey-0.2.0 vs lib/domkey/view/labeled_group.rb in domkey-0.3.0

- old
+ new

@@ -14,14 +14,35 @@ def initialize group __setobj__(group) end + def before_set + __getobj__.set false + end + # @param value [String] a label text to set a corresponding element referenced # @param value [Array<String>] one or more labels def set value - __getobj__.set false + before_set + set_strategy(value) + end + + # @return [Array<String>] label texts for selected elements + def value + selected_ones = __getobj__.find_all { |e| e.element.set? } + LabelMapper.for(selected_ones).map { |e| e.element.text } + end + + # @return [Array<String>] label texts for all elements in a group + def options + LabelMapper.for(__getobj__).map { |e| e.element.text } + end + + private + + def set_strategy value labels = self.options indices = [*value].map do |what| i = case what when String labels.index(what) @@ -33,18 +54,8 @@ indices.each do |i| __getobj__[i].element.set end end - # @return [Array<String>] label texts for selected elements - def value - selected_ones = __getobj__.find_all { |e| e.element.set? } - LabelMapper.for(selected_ones).map { |e| e.element.text } - end - - # @return [Array<String>] label texts for all elements in a group - def options - LabelMapper.for(__getobj__).map { |e| e.element.text } - end end end end