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.



1861
1862
1863
1864
1865
1866
# File 'lib/oktest.rb', line 1861

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.



1868
1869
1870
# File 'lib/oktest.rb', line 1868

def negative
  @negative
end

#spec_patternObject (readonly)

Returns the value of attribute spec_pattern.



1868
1869
1870
# File 'lib/oktest.rb', line 1868

def spec_pattern
  @spec_pattern
end

#tag_patternObject (readonly)

Returns the value of attribute tag_pattern.



1868
1869
1870
# File 'lib/oktest.rb', line 1868

def tag_pattern
  @tag_pattern
end

#topic_patternObject (readonly)

Returns the value of attribute topic_pattern.



1868
1869
1870
# File 'lib/oktest.rb', line 1868

def topic_pattern
  @topic_pattern
end

Class Method Details

.create_from(pattern) ⇒ Object

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



1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
# File 'lib/oktest.rb', line 1870

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



1929
1930
1931
# File 'lib/oktest.rb', line 1929

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

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

Returns:

  • (Boolean)


1887
1888
1889
1890
1891
# File 'lib/oktest.rb', line 1887

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)


1903
1904
1905
1906
1907
1908
1909
# File 'lib/oktest.rb', line 1903

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)


1894
1895
1896
1897
1898
1899
1900
# File 'lib/oktest.rb', line 1894

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