Sha256: 12408e5c952951e886fdb08ceada7a715a2bdd49a80c1c1a942b5b0448d59318

Contents?: true

Size: 794 Bytes

Versions: 1

Compression:

Stored size: 794 Bytes

Contents

module Formulaic
  module Inputs
    class ArrayInput < Input
      def fill
        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'

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
formulaic-0.4.1 lib/formulaic/inputs/array_input.rb