class Hasta::Filter
The filter that is used to drop unwanted lines from input files
Public Class Methods
from_file(file)
click to toggle source
# File lib/hasta/filter.rb, line 8 def self.from_file(file) if lines = File.read(file) Hasta.logger.debug "Loading data filter file: #{File.expand_path(file)}" new(*lines.split("\n").map { |line| Regexp.new(line) }) end rescue => ex raise ConfigurationError.new, "Failed to load filter configuration file: #{file} - #{ex.message}" end
new(*accept_regexes)
click to toggle source
# File lib/hasta/filter.rb, line 18 def initialize(*accept_regexes) @accept_regexes = Set.new(accept_regexes) end
Public Instance Methods
include?(line)
click to toggle source
# File lib/hasta/filter.rb, line 22 def include?(line) to_proc.call(line) end
to_proc()
click to toggle source
# File lib/hasta/filter.rb, line 26 def to_proc @proc ||= Proc.new { |line| !!(accept_regexes.find { |regex| line =~ regex }) } end
to_s()
click to toggle source
# File lib/hasta/filter.rb, line 30 def to_s "#<#{self.class.name}:#{accept_regexes.to_a.inspect}>" end
Private Instance Methods
accept_regexes()
click to toggle source
# File lib/hasta/filter.rb, line 36 def accept_regexes @accept_regexes.to_a.sort_by(&:inspect) end