module Selector

Composable filters for lists of values

Constants

NOTHING
VERSION

The semantic version of the gem. @see semver.org/ Semantic versioning 2.0

Public Class Methods

build(clause) click to toggle source

Factory method that builds a condition instance depending on argument type

@param [Object] clause

@return [Selector::Condition]

# File lib/selector.rb, line 42
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) click to toggle source

Creates a condition from options

@param [Hash] options

@return [Selector::Condition]

# File lib/selector.rb, line 30
def self.new(options)
  white = options.fetch(:only)   { ANYTHING }
  black = options.fetch(:except) { NOTHING  }
  build(white) - build(black)
end