Class: VinaryTree::Liblevenshtein::PhoneticPattern

Inherits:
Object
  • Object
show all
Defined in:
lib/vinary_tree/liblevenshtein.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pointer) ⇒ PhoneticPattern

Returns a new instance of PhoneticPattern.



224
225
226
227
# File 'lib/vinary_tree/liblevenshtein.rb', line 224

def initialize(pointer)
  @handle = ConcurrentHandle.new(pointer, Native.method(:llev_phonetic_pattern_free))
  ObjectSpace.define_finalizer(self, ConcurrentHandle.finalizer(@handle))
end

Class Method Details

.compile(source, llre) ⇒ Object



217
218
219
220
221
222
# File 'lib/vinary_tree/liblevenshtein.rb', line 217

def self.compile(source, llre)
  output = Native.pointer_output
  status = llre ? Native.llev_phonetic_pattern_compile_llre(source.b, source.bytesize, output) : Native.llev_phonetic_pattern_compile_regex(source.b, source.bytesize, output)
  Liblevenshtein.check(status)
  new(Native.read_pointer(output))
end

.compile_llre(source) ⇒ Object



216
# File 'lib/vinary_tree/liblevenshtein.rb', line 216

def self.compile_llre(source) = compile(source, true)

.compile_regex(source) ⇒ Object



215
# File 'lib/vinary_tree/liblevenshtein.rb', line 215

def self.compile_regex(source) = compile(source, false)

Instance Method Details

#closeObject



242
243
244
# File 'lib/vinary_tree/liblevenshtein.rb', line 242

def close
  @handle.close; ObjectSpace.undefine_finalizer(self); nil
end

#matches?(text) ⇒ Boolean

Returns:

  • (Boolean)


228
229
230
231
232
233
234
# File 'lib/vinary_tree/liblevenshtein.rb', line 228

def matches?(text)
  with_pointer do |pointer|
    output = Fiddle::Pointer.malloc(1, Fiddle::RUBY_FREE)
    Liblevenshtein.check(Native.llev_phonetic_pattern_matches(pointer, text.b, text.bytesize, output))
    output[0].positive?
  end
end

#sizeObject



235
236
237
238
239
240
241
# File 'lib/vinary_tree/liblevenshtein.rb', line 235

def size
  with_pointer do |pointer|
    states = Native.size_output; transitions = Native.size_output
    Liblevenshtein.check(Native.llev_phonetic_pattern_size(pointer, states, transitions))
    [Native.read_size(states), Native.read_size(transitions)]
  end
end