Class: Dcm::VariantFilter

Inherits:
Object show all
Defined in:
lib/variant_filter.rb

Constant Summary collapse

ALLOWED_FILTERKEYS =
%w(swfk_id typekey devkey)

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#keyObject (readonly)

Returns the value of attribute key.



5
6
7
# File 'lib/variant_filter.rb', line 5

def key
  @key
end

#matchersObject (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

Returns:

  • (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_sObject



25
# File 'lib/variant_filter.rb', line 25

def to_s = "<Filter #{key}:#{matchers.join(",")}"