source "https://rubygems.org"
gem "interscript", "~>2.0"
Interscript can be used as a Ruby Gem library to be integrated with other Ruby applications.
Gemfile
You need to make sure your Gemfile contains the following lines:
Requiring
In your codebase, if you don’t do Bundler.require
, you will need to add the
following line:
require "interscript"
Listing all available maps
To list all available maps, one must execute the following code:
maps = Interscript.maps
maps
will be an array containing all Interscript maps by their name.
Transliterating text
To transliterate test using a given map, like bas-rus-Cyrl-Latn-2017-bss
,
one must execute:
cache = {}
input = "Хелло"
output = Interscript.transliterate("bas-rus-Cyrl-Latn-2017-bss",
input,
cache)
You should preserve the cache
variable for performance reasons. It is optional,
you don’t need to (but should) supply it.
Using Ruby compiler
If performance is of utmost performance for your application and you want to
sacrifice a little bit of loading time for much better performance, you can use
Interscript::Compiler::Ruby
instead of Interscript::Interpreter
(which is
used by default).
require "interscript/compiler/ruby"
cache = {}
input = "Хелло"
output = Interscript.transliterate("bas-rus-Cyrl-Latn-2017-bss",
input,
cache,
compiler: Interscript::Compiler::Ruby)
Transliterating in reverse
To reverse a given string using a map with a name of a form:
bas-rus-Cyrl-Latn-2017-bss
, change places for Cyrl and Latn.
To reverse a given string using a map with a name of a form:
var-swe-Latn-Latn-2021
, append -reverse
to its name.
Please note: this only works for Ruby implementation. Other implementations depend on the Ruby implementation for the purpose of compilation. For those, you need to compile the map using the Ruby implementation, but the name has to be given according to the above hint.