Class: Nodepile::InputColumnSpecs::PatternMatchVerifier

Inherits:
Object
  • Object
show all
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

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.

Parameters:

  • test_id_string (String)

Returns:

  • (Boolean)


313
# File 'lib/nodepile/colspecs.rb', line 313

def id_match?(test_id_string) = @id_test.call(test_id_string)

#inspectObject



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

Returns:

  • (Boolean)


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.

Parameters:

  • node_entity_packet (Nodepile::EntityPacket)

Returns:

  • (Boolean)


318
# File 'lib/nodepile/colspecs.rb', line 318

def non_id_match?(node_entity_packet) = @non_id_test.call(node_entity_packet)