Class: Oktest::Filter

Inherits:
Visitor show all
Defined in:
lib/oktest.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Visitor

#start

Constructor Details

#initialize(topic_pattern, spec_pattern, tag_pattern, negative: false) ⇒ Filter

Returns a new instance of Filter.



2353
2354
2355
2356
2357
2358
# File 'lib/oktest.rb', line 2353

def initialize(topic_pattern, spec_pattern, tag_pattern, negative: false)
  @topic_pattern = topic_pattern
  @spec_pattern  = spec_pattern
  @tag_pattern   = tag_pattern
  @negative      = negative
end

Instance Attribute Details

#negativeObject (readonly)

Returns the value of attribute negative.



2360
2361
2362
# File 'lib/oktest.rb', line 2360

def negative
  @negative
end

#spec_patternObject (readonly)

Returns the value of attribute spec_pattern.



2360
2361
2362
# File 'lib/oktest.rb', line 2360

def spec_pattern
  @spec_pattern
end

#tag_patternObject (readonly)

Returns the value of attribute tag_pattern.



2360
2361
2362
# File 'lib/oktest.rb', line 2360

def tag_pattern
  @tag_pattern
end

#topic_patternObject (readonly)

Returns the value of attribute topic_pattern.



2360
2361
2362
# File 'lib/oktest.rb', line 2360

def topic_pattern
  @topic_pattern
end

Class Method Details

.create_from(pattern) ⇒ Object

ex: ‘topic=name’, ‘spec=“pat”’



2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
# File 'lib/oktest.rb', line 2362

def self.create_from(pattern)  # ex: 'topic=name', 'spec="*pat*"'
  #; [!gtpt1] parses 'sid=...' as filter pattern for spec.
  pattern = "spec#{$1}\\[!#{$2}\\]*" if pattern =~ /\Asid(=|!=)(.*)/  # filter by spec id
  #; [!xt364] parses 'topic=...' as filter pattern for topic.
  #; [!53ega] parses 'spec=...' as filter pattern for spec.
  #; [!go6us] parses 'tag=...' as filter pattern for tag.
  #; [!cmp6e] raises ArgumentError when invalid argument.
  pat = {'topic'=>nil, 'spec'=>nil, 'tag'=>nil}
  pattern =~ /\A(\w+)(=|!=)/ && pat.key?($1)  or
    raise ArgumentError, "#{pattern.inspect}: unexpected pattern string."
  pat[$1] = $'
  #; [!5hl7z] parses 'xxx!=...' as negative filter pattern.
  negative = ($2 == '!=')
  #; [!9dzmg] returns filter object.
  return self.new(pat['topic'], pat['spec'], pat['tag'], negative: negative)
end

Instance Method Details

#filter_children!(node) ⇒ Object



2421
2422
2423
# File 'lib/oktest.rb', line 2421

def filter_children!(node)
  _filter_children!(node)
end

#scope_match?(scope) ⇒ Boolean Also known as: visit_scope

Returns:

  • (Boolean)


2379
2380
2381
2382
2383
# File 'lib/oktest.rb', line 2379

def scope_match?(scope)
  #; [!zkq6r] returns true only if tag name matched to pattern.
  return true if @tag_pattern && _match_tag?(scope.tag, @tag_pattern)
  return false
end

#spec_match?(spec) ⇒ Boolean Also known as: visit_spec

Returns:

  • (Boolean)


2395
2396
2397
2398
2399
2400
2401
# File 'lib/oktest.rb', line 2395

def spec_match?(spec)
  #; [!k45p3] returns true if spec description matched to pattern.
  #; [!li3pd] returns true if tag name matched to pattern.
  return true if @spec_pattern && _match?(spec.desc, @spec_pattern)
  return true if @tag_pattern && _match_tag?(spec.tag, @tag_pattern)
  return false
end

#topic_match?(topic) ⇒ Boolean Also known as: visit_topic

Returns:

  • (Boolean)


2386
2387
2388
2389
2390
2391
2392
# File 'lib/oktest.rb', line 2386

def topic_match?(topic)
  #; [!jpycj] returns true if topic target name matched to pattern.
  #; [!6lfp1] returns true if tag name matched to pattern.
  return true if @topic_pattern && _match?(topic.target.to_s, @topic_pattern)
  return true if @tag_pattern && _match_tag?(topic.tag, @tag_pattern)
  return false
end