module Dcm class VariantFilter ALLOWED_FILTERKEYS = %w(swfk_id typekey devkey) attr_reader :key, :matchers 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 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 def to_s = "