lib/formulaic/inputs/array_input.rb in formulaic-0.1.1 vs lib/formulaic/inputs/array_input.rb in formulaic-0.1.2
- old
+ new
@@ -1,9 +1,40 @@
module Formulaic
module Inputs
class ArrayInput < Input
+ def initialize(label, value)
+ @label = label
+ @value = value
+ end
+
def fill
- value.each { |checkbox| check checkbox }
+ attempt_to_fill_selects ||
+ attempt_to_fill_checkboxes ||
+ raise_input_error
end
+
+ private
+
+ def attempt_to_fill_selects
+ SelectInput.new(label, value).fill
+ end
+
+ def attempt_to_fill_checkboxes
+ CheckboxInput.new(label, value).fill
+ end
+
+ def contains_all_options?(nodes)
+ nodes.map(&:text).to_set.superset?(value.to_set)
+ end
+
+ def raise_input_error
+ raise(
+ InputNotFound,
+ %[Unable to find checkboxes or select[multiple] "#{label}" containing all options #{value.inspect}.]
+ )
+ end
end
end
end
+
+require 'formulaic/inputs/checkbox_input'
+require 'formulaic/inputs/select_input'