Class: Selector::Regexp
Overview
The condition checks if a value matches the regexp
Instance Attribute Summary
Attributes inherited from Condition
Instance Method Summary collapse
-
#[](value) ⇒ Boolean
Checks if the stringified value matches the regexp.
-
#initialize(_) ⇒ Regexp
constructor
Initializes the condition with the regexp.
-
#|(other) ⇒ Object
Creates an OR composition.
Methods inherited from Condition
#!, #&, #-, #==, #attribute
Constructor Details
#initialize(_) ⇒ Regexp
Initializes the condition with the regexp
15 16 17 |
# File 'lib/selector/regexp.rb', line 15 def initialize(_) super end |
Instance Method Details
#[](value) ⇒ Boolean
Checks if the stringified value matches the regexp
30 31 32 |
# File 'lib/selector/regexp.rb', line 30 def [](value) value.to_s[attribute] ? true : false end |
#|(other) ⇒ Object
Creates an OR composition
If other value is a regexp, then creates modified regexp to avoid nesting
42 43 44 45 |
# File 'lib/selector/regexp.rb', line 42 def |(other) return super unless other.instance_of? Regexp Regexp.new(/(#{attribute})|(#{other.attribute})/) end |