class Selector::Regexp

The condition checks if a value matches the regexp

@example (see [])

Public Class Methods

new(_) click to toggle source

@!method initialize(regexp) Initializes the condition with the regexp

@param [::Regexp] regexp

Calls superclass method Selector::Condition::new
# File lib/selector/regexp.rb, line 16
def initialize(_)
  super
end

Public Instance Methods

[](value) click to toggle source

Checks if the stringified value matches the regexp

@example

condition = Selector::Regexp.new /1/
condition[11] # => true
condition[22] # => false

@param (see Selector::Condition#[])

@return (see Selector::Condition#[])

# File lib/selector/regexp.rb, line 31
def [](value)
  value.to_s[attribute] ? true : false
end
|(other) click to toggle source

Creates an OR composition

If other value is a regexp, then creates modified regexp to avoid nesting

@param (see Selector::Composition#|)

@return (see Selector::Composition#|)

Calls superclass method Selector::Condition#|
# File lib/selector/regexp.rb, line 43
def |(other)
  return super unless other.instance_of? Regexp
  Regexp.new(/(#{attribute})|(#{other.attribute})/)
end