Class: VinaryTree::Liblevenshtein::PhoneticRuleSet

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

Constant Summary collapse

ENGLISH_ORTHOGRAPHY =
0
ENGLISH_PHONETIC =
1

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pointer) ⇒ PhoneticRuleSet

Returns a new instance of PhoneticRuleSet.



260
261
262
263
# File 'lib/vinary_tree/liblevenshtein.rb', line 260

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

Class Method Details

.builtin(kind) ⇒ Object



257
258
259
# File 'lib/vinary_tree/liblevenshtein.rb', line 257

def self.builtin(kind)
  output = Native.pointer_output; Liblevenshtein.check(Native.llev_phonetic_rules_builtin(kind, output)); new(Native.read_pointer(output))
end

.parse(source) ⇒ Object



254
255
256
# File 'lib/vinary_tree/liblevenshtein.rb', line 254

def self.parse(source)
  output = Native.pointer_output; Liblevenshtein.check(Native.llev_phonetic_rules_parse(source.b, source.bytesize, output)); new(Native.read_pointer(output))
end

Instance Method Details

#apply(text) ⇒ Object



269
270
271
272
273
274
275
276
277
# File 'lib/vinary_tree/liblevenshtein.rb', line 269

def apply(text)
  with_pointer do |pointer|
    output = Native::OwnedString.malloc
    Liblevenshtein.check(Native.llev_phonetic_rules_apply(pointer, text.b, text.bytesize, output))
    begin Fiddle::Pointer.new(output.data)[0, output.len].force_encoding(Encoding::UTF_8)
    ensure Native.llev_owned_string_free(output)
    end
  end
end

#closeObject



278
279
280
# File 'lib/vinary_tree/liblevenshtein.rb', line 278

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

#lengthObject



264
265
266
267
268
# File 'lib/vinary_tree/liblevenshtein.rb', line 264

def length
  with_pointer do |pointer|
    output = Native.size_output; Liblevenshtein.check(Native.llev_phonetic_rules_len(pointer, output)); Native.read_size(output)
  end
end