Sha256: 8ec403ddea2a6d686308902359f9068fb8cf34fd2e653febd89f36b5f5fb80cb

Contents?: true

Size: 1.03 KB

Versions: 15

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true
require 'capybara/selector/filter'

module Capybara
  class Selector
    class FilterSet
      attr_reader :descriptions

      def initialize(name, &block)
        @name = name
        @descriptions = []
        instance_eval(&block)
      end

      def filter(name, *types_and_options, &block)
        options = types_and_options.last.is_a?(Hash) ? types_and_options.pop.dup : {}
        types_and_options.each { |k| options[k] = true}
        filters[name] = Filter.new(name, block, options)
      end

      def describe(&block)
        descriptions.push block
      end

      def description(options={})
        @descriptions.map {|desc| desc.call(options).to_s }.join
      end

      def filters
        @filters ||= {}
      end

      class << self
        def all
          @filter_sets ||= {}
        end

        def add(name, &block)
          all[name.to_sym] = FilterSet.new(name.to_sym, &block)
        end

        def remove(name)
          all.delete(name.to_sym)
        end
      end
    end
  end
end

Version data entries

15 entries across 14 versions & 3 rubygems

Version Path
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/capybara-2.13.0/lib/capybara/selector/filter_set.rb
tdiary-5.0.5 vendor/bundle/gems/capybara-2.13.0/lib/capybara/selector/filter_set.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/capybara-2.14.0/lib/capybara/selector/filter_set.rb
capybara-2.14.0 lib/capybara/selector/filter_set.rb
tdiary-5.0.4 vendor/bundle/gems/capybara-2.13.0/lib/capybara/selector/filter_set.rb
capybara-2.13.0 lib/capybara/selector/filter_set.rb
capybara-2.12.1 lib/capybara/selector/filter_set.rb
capybara-2.12.0 lib/capybara/selector/filter_set.rb
capybara-2.11.0 lib/capybara/selector/filter_set.rb
capybara-2.10.2 lib/capybara/selector/filter_set.rb
capybara-2.10.1 lib/capybara/selector/filter_set.rb
capybara-2.10.0 lib/capybara/selector/filter_set.rb
capybara-2.9.2 lib/capybara/selector/filter_set.rb
capybara-2.9.1 lib/capybara/selector/filter_set.rb
capybara-2.9.0 lib/capybara/selector/filter_set.rb