/
filter_set.rb
44 lines (30 loc) · 1.1 KB
/
filter_set.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
require "cuke_slicer/helpers/helpers"
require "cuke_slicer/collections/tag_collection"
require "cuke_slicer/collections/path_collection"
# Internal helper module that is not part of the public API. Subject to change at any time.
# :nodoc: all
module CukeSlicer
class FilterSet
include Helpers
def initialize filter_type, filter_value
self.filter_type = filter_type
self.filter_value = filter_value
end
def validate
block_unknown
block_invalid
if filter_value.is_a?(Array)
TagCollection.new(filter_value).validate if is_tag?(filter_type)
PathCollection.new(filter_value).validate if is_path?(filter_type)
end
end
private
def block_unknown
raise(ArgumentError, "Unknown filter '#{filter_type}'") unless CukeSlicer::Slicer.known_filters.include?(filter_type)
end
def block_invalid
raise(ArgumentError, "Invalid filter '#{filter_value}'. Must be a String, Regexp, or Array thereof. Got #{filter_value.class}") unless str_regex_arr?(filter_value)
end
attr_accessor :filter_type, :filter_value
end
end