Class: Dcm::VariantFilter
Constant Summary collapse
- ALLOWED_FILTERKEYS =
%w(swfk_id typekey devkey)
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#matchers ⇒ Object
readonly
Returns the value of attribute matchers.
Instance Method Summary collapse
-
#initialize(expr) ⇒ VariantFilter
constructor
A new instance of VariantFilter.
- #match?(headers, row) ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(expr) ⇒ VariantFilter
Returns a new instance of VariantFilter.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/variant_filter.rb', line 6 def initialize(expr) unless expr.match?(/^[\w_]+\:/) && ALLOWED_FILTERKEYS.include?(expr.split(":").first) fail "Unknown filter expression #{expr}. " + "Syntax: (#{ALLOWED_FILTERKEYS.join("|")}):value[,value2]." end key, matchers = expr.split(":") @key = key.to_sym @matchers = matchers.split(",").map { /#{_1}/i } end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
5 6 7 |
# File 'lib/variant_filter.rb', line 5 def key @key end |
#matchers ⇒ Object (readonly)
Returns the value of attribute matchers.
5 6 7 |
# File 'lib/variant_filter.rb', line 5 def matchers @matchers end |
Instance Method Details
#match?(headers, row) ⇒ Boolean
17 18 19 20 21 22 23 |
# File 'lib/variant_filter.rb', line 17 def match?(headers, row) return false unless row[3] return false unless row[3].match?(/CVAR/) return false unless headers.include?(@key) matchers.any? { row[headers.index(@key)].match?(_1) } end |
#to_s ⇒ Object
25 |
# File 'lib/variant_filter.rb', line 25 def to_s = "<Filter #{key}:#{matchers.join(",")}" |