Module: Selector
- Defined in:
- lib/selector.rb,
lib/selector/or.rb,
lib/selector/and.rb,
lib/selector/not.rb,
lib/selector/array.rb,
lib/selector/regexp.rb,
lib/selector/nothing.rb,
lib/selector/anything.rb,
lib/selector/function.rb,
lib/selector/condition.rb,
lib/selector/collection.rb
Overview
Composable filters for lists of values
Defined Under Namespace
Classes: And, Anything, Array, Collection, Condition, Function, Not, Nothing, Or, Regexp
Class Method Summary collapse
-
.build(clause) ⇒ Selector::Condition
Factory method that builds a condition instance depending on argument type.
-
.new(options) ⇒ Selector::Condition
Creates a condition from options.
Class Method Details
.build(clause) ⇒ Selector::Condition
Factory method that builds a condition instance depending on argument type
41 42 43 44 45 46 47 48 |
# File 'lib/selector.rb', line 41 def self.build(clause) return clause if [ANYTHING, NOTHING].include? clause return Regexp.new(clause) if clause.instance_of? ::Regexp return Array.new(clause) if [::Array, Set].include? clause.class return Collection.new(clause) if clause.is_a? Enumerable return Function.new(clause) if clause.respond_to? :call Array.new [clause] end |
.new(options) ⇒ Selector::Condition
Creates a condition from options
29 30 31 32 33 |
# File 'lib/selector.rb', line 29 def self.new() white = .fetch(:only) { ANYTHING } black = .fetch(:except) { NOTHING } build(white) - build(black) end |