Class: MemDB::Index::PatternMatch

Inherits:
Object
  • Object
show all
Includes:
MemDB::Index
Defined in:
lib/mem_db/index/pattern_match.rb

Defined Under Namespace

Classes: Bucket

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MemDB::Index

compose

Constructor Details

#initialize(idx:, bucket: MemDB::Bucket) ⇒ PatternMatch

Returns a new instance of PatternMatch.



30
31
32
33
# File 'lib/mem_db/index/pattern_match.rb', line 30

def initialize(idx:, bucket: MemDB::Bucket)
  @idx = idx
  @bucket = bucket
end

Instance Attribute Details

#bucketObject (readonly)

Returns the value of attribute bucket.



28
29
30
# File 'lib/mem_db/index/pattern_match.rb', line 28

def bucket
  @bucket
end

#idxObject (readonly)

Returns the value of attribute idx.



28
29
30
# File 'lib/mem_db/index/pattern_match.rb', line 28

def idx
  @idx
end

Instance Method Details

#add(obj, value) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/mem_db/index/pattern_match.rb', line 35

def add(obj, value)
  obj.idx_value(@idx).each do |pattern|
    type = pattern[0]
    sequence = pattern[1]
    index =
      case type
      when :enum
        enums
      when :prefix
        prefixes
      when :suffix
        suffixes
      when :substring
        substrings
      end

    obj[self] = sequence
    index.add(obj, value)
    obj.delete(self)
  end
end

#query(query, out: MemDB::Out.new) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/mem_db/index/pattern_match.rb', line 57

def query(query, out: MemDB::Out.new)
  query.idx_value(@idx).each do |q|
    query[self] = q

    @enums&.query(query, out: out)
    @suffixes&.query(query, out: out)
    @prefixes&.query(query, out: out)
    @substrings&.query(query, out: out)

    query.delete(self)
  end

  out
end