Module: Sanscript

Defined in:
lib/sanscript.rb,
lib/sanscript/detect.rb,
lib/sanscript/version.rb,
lib/sanscript/benchmark.rb,
lib/sanscript/refinements.rb,
lib/sanscript/transliterate.rb,
lib/sanscript/transliterate/schemes.rb

Overview

Sanscript.rb detection/transliteration module for Sanskrit.

Defined Under Namespace

Modules: Benchmark, Detect, Refinements, Transliterate

Constant Summary collapse

VERSION =

The version number

"0.4.0"

Class Method Summary collapse

Class Method Details

.detect(text) ⇒ Symbol?

Attempts to detect the encoding scheme of the provided string. Simple proxy for Sanscript::Detect.detect_scheme

Parameters:

  • text (String)

    a string of Sanskrit text

Returns:

  • (Symbol, nil)

    the Symbol of the scheme, or nil if no match



16
17
18
# File 'lib/sanscript.rb', line 16

def detect(text)
  Detect.detect_scheme(text)
end

.transliterate(text, from, to, **opts) ⇒ String .transliterate(text, to, **opts) ⇒ String?

Transliterates a string, optionally detecting its source-scheme first.

Overloads:

  • .transliterate(text, from, to, **opts) ⇒ String

    Returns the transliterated String.

    Parameters:

    • text (String)

      the String to transliterate

    • from (Symbol)

      the name of the scheme to transliterate from

    • to (Symbol)

      the name of the scheme to transliterate to

    Options Hash (**opts):

    • :skip_sgml (Boolean) — default: false

      escape SGML-style tags in text string

    • :syncope (Boolean) — default: false

      activate Hindi-style schwa syncope

    Returns:

    • (String)

      the transliterated String

  • .transliterate(text, to, **opts) ⇒ String?

    Returns the transliterated String, or nil if detection and fallback fail.

    Parameters:

    • text (String)

      the String to transliterate

    • to (Symbol)

      the name of the scheme to transliterate to

    Options Hash (**opts):

    • :default_scheme (Symbol)

      a default scheme to fall-back to if detection fails

    • :skip_sgml (Boolean) — default: false

      escape SGML-style tags in text string

    • :syncope (Boolean) — default: false

      activate Hindi-style schwa syncope

    Returns:

    • (String, nil)

      the transliterated String, or nil if detection and fallback fail



37
38
39
40
41
42
43
# File 'lib/sanscript.rb', line 37

def transliterate(text, from, to = nil, **opts)
  if to.nil?
    to = from
    from = Detect.detect_scheme(text) || opts[:default_scheme] || return
  end
  Transliterate.transliterate(text, from, to, opts)
end