Sha256: da7e1cbca32bff70a8d6c25ddba7fcbbcce66d3c0bceba07782bceebf08d1d4f

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 KB

Contents

require "koko_keywords/version"
require 'ffi'
require 'etc'

module KokoKeywords
  module NativeWrapper
    def self.lib_path
      uname = Etc.uname

      filename = 'libkoko_keywords'

      if ENV["KOKO_LIB_PATH"]
          return ENV["KOKO_LIB_PATH"]
      elsif uname[:sysname] == 'Darwin' and (uname[:machine] == 'arm64' || uname[:machine] == 'aarch64')
          filename = filename + '_arm64.dylib'
      elsif uname[:sysname] == 'Darwin' and uname[:machine] == 'x86_64'
          filename = filename + '_x86_64.dylib'
      elsif uname[:sysname] == 'Linux' and uname[:machine] == 'x86_64'
          filename = filename + '_x86_64.so'
      elsif uname[:sysname] == 'Linux' and (uname[:machine] == 'arm64' || uname[:machine] == 'aarch64')
          filename = filename + '_arm64.so'
      else
        raise RuntimeError.new("Unsupported platform #{uname[:sysname]}, #{uname[:machine]} contact api@kokocares.org for support")
      end

      __dir__ + '/../clib/' + filename
    end

    extend FFI::Library
    ffi_lib lib_path
    attach_function :c_koko_keywords_match, [:string, :string], :int
    attach_function :c_koko_keywords_error_description, [:int], :string
  end


  def self.match(text, filters: "")
    match_value = NativeWrapper.c_koko_keywords_match(text, filters)

    if match_value < 0
      raise RuntimeError.new(NativeWrapper.c_koko_keywords_error_description(match_value))
    end

    !match_value.zero?
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
koko_keywords-0.3.2 lib/koko_keywords.rb