class MemDB::Field::Pattern::Pattern

Constants

WILDCARD

Public Class Methods

new(source) click to toggle source
# File lib/mem_db/field/pattern.rb, line 57
def initialize(source)
  wildcard_count = source.count(WILDCARD)
  @pat =
    if wildcard_count.zero?
      Exact.new(source)
    elsif wildcard_count > 1
      Rx.new(source)
    elsif source.end_with?(WILDCARD)
      Prefix.new(source[0..-2])
    elsif source.start_with?(WILDCARD)
      Suffix.new(source[1..-1])
    else
      Rx.new(source)
    end
end

Public Instance Methods

match?(str) click to toggle source
# File lib/mem_db/field/pattern.rb, line 73
def match?(str)
  @pat.match?(str)
end