Class: Nodepile::InputColumnSpecs::PatternMatchVerifier
- Inherits:
-
Object
- Object
- Nodepile::InputColumnSpecs::PatternMatchVerifier
- Defined in:
- lib/nodepile/colspecs.rb
Overview
Utility class returned by the #make_pattern_match_verifier() method
It holds tests that can be used to confirm whether a pattern matches aspects of a given node.
Example Pattern Strings:
1) "?/^alpha/" matches type == :node where key starts with "alpha"
2) "beta" mates type == :node where key is exactly "beta"
Constant Summary collapse
- ALWAYS_TRUE_PROC =
Proc.new{true}
Instance Method Summary collapse
-
#id_match?(test_id_string) ⇒ Boolean
Exclusively test whether the given node id would be acceptable for this verifier.
-
#initialize(pattern_string) ⇒ PatternMatchVerifier
constructor
A new instance of PatternMatchVerifier.
- #inspect ⇒ Object
-
#match?(nep) ⇒ Boolean
Perform both the id_match?() and return their logical AND.
-
#non_id_match?(node_entity_packet) ⇒ Boolean
Exclusively test whether any of the non-id aspects of the node would be acceptable for this verifier.
Constructor Details
#initialize(pattern_string) ⇒ PatternMatchVerifier
Returns a new instance of PatternMatchVerifier.
291 292 293 294 295 296 297 298 299 300 301 302 303 |
# File 'lib/nodepile/colspecs.rb', line 291 def initialize(pattern_string) @non_id_test = ALWAYS_TRUE_PROC @id_test = nil @pattern_string = pattern_string case pattern_string when /^\s*\?\s*\/(.*)\/\s*$/ rx = Regexp.new($1) @id_test = Proc.new{|id| rx.match?(id)} else exact_id = pattern_string.strip # match with the exact (trimmed) string @id_test = Proc.new{|id| id == exact_id } end end |
Instance Method Details
#id_match?(test_id_string) ⇒ Boolean
Exclusively test whether the given node id would be acceptable for this verifier.
313 |
# File 'lib/nodepile/colspecs.rb', line 313 def id_match?(test_id_string) = @id_test.call(test_id_string) |
#inspect ⇒ Object
306 |
# File 'lib/nodepile/colspecs.rb', line 306 def inspect = "#<#{self.class} 0x#{object_id} pattern_string=#{@pattern_string.inspect}> " |
#match?(nep) ⇒ Boolean
Perform both the id_match?() and return their logical AND
321 |
# File 'lib/nodepile/colspecs.rb', line 321 def match?(nep) = id_match?(nep.key) && non_id_match?(nep) |
#non_id_match?(node_entity_packet) ⇒ Boolean
Exclusively test whether any of the non-id aspects of the node would be acceptable for this verifier.
318 |
# File 'lib/nodepile/colspecs.rb', line 318 def non_id_match?(node_entity_packet) = @non_id_test.call(node_entity_packet) |