Module: Sanscript::Transliterate
- Defined in:
- lib/sanscript/transliterate.rb,
lib/sanscript/transliterate/schemes.rb
Class Attribute Summary collapse
-
.all_alternates ⇒ Object
readonly
Returns the value of attribute all_alternates.
-
.defaults ⇒ Object
readonly
Returns the value of attribute defaults.
-
.roman_schemes ⇒ Object
readonly
Returns the value of attribute roman_schemes.
-
.schemes ⇒ Object
readonly
Returns the value of attribute schemes.
Class Method Summary collapse
-
.add_brahmic_scheme(name, scheme) ⇒ Object
Add a Brahmic scheme to Sanscript.
-
.add_roman_scheme(name, scheme) ⇒ Object
Add a roman scheme to Sanscript.
-
.roman_scheme?(name) ⇒ Boolean
Check whether the given scheme encodes romanized Sanskrit.
-
.scheme_names ⇒ Object
Return a list of available schemes.
-
.transliterate(data, from, to, options = {}) ⇒ Object
/** Transliterate from one script to another.
Class Attribute Details
.all_alternates ⇒ Object (readonly)
Returns the value of attribute all_alternates.
17 18 19 |
# File 'lib/sanscript/transliterate.rb', line 17 def all_alternates @all_alternates end |
.defaults ⇒ Object (readonly)
Returns the value of attribute defaults.
17 18 19 |
# File 'lib/sanscript/transliterate.rb', line 17 def defaults @defaults end |
.roman_schemes ⇒ Object (readonly)
Returns the value of attribute roman_schemes.
17 18 19 |
# File 'lib/sanscript/transliterate.rb', line 17 def roman_schemes @roman_schemes end |
.schemes ⇒ Object (readonly)
Returns the value of attribute schemes.
17 18 19 |
# File 'lib/sanscript/transliterate.rb', line 17 def schemes @schemes end |
Class Method Details
.add_brahmic_scheme(name, scheme) ⇒ Object
Add a Brahmic scheme to Sanscript.
Schemes are of two types: “Brahmic” and “roman”. Brahmic consonants have an inherent vowel sound, but roman consonants do not. This is the main difference between these two types of scheme.
A scheme definition is an object (“{}”) that maps a group name to a list of characters. For illustration, see the “devanagari” scheme at the top of this file.
You can use whatever group names you like, but for the best results, you should use the same group names that Sanscript does.
66 67 68 |
# File 'lib/sanscript/transliterate.rb', line 66 def add_brahmic_scheme(name, scheme) @schemes[name.to_sym] = scheme.deep_dup.deep_freeze end |
.add_roman_scheme(name, scheme) ⇒ Object
Add a roman scheme to Sanscript.
See the comments on Sanscript.add_brahmic_scheme. The “vowel_marks” field can be omitted.
79 80 81 82 83 84 85 |
# File 'lib/sanscript/transliterate.rb', line 79 def add_roman_scheme(name, scheme) name = name.to_sym scheme = scheme.deep_dup scheme[:vowel_marks] = scheme[:vowels][1..-1] unless scheme.key?(:vowel_marks) @schemes[name] = scheme.deep_freeze @roman_schemes.add(name) end |
.roman_scheme?(name) ⇒ Boolean
Check whether the given scheme encodes romanized Sanskrit.
@param name the scheme name
@return boolean
44 45 46 |
# File 'lib/sanscript/transliterate.rb', line 44 def roman_scheme?(name) @roman_schemes.include?(name.to_sym) end |
.scheme_names ⇒ Object
Return a list of available schemes.
@return array of scheme identifiers
34 35 36 |
# File 'lib/sanscript/transliterate.rb', line 34 def scheme_names @schemes.keys.sort! end |
.transliterate(data, from, to, options = {}) ⇒ Object
/** Transliterate from one script to another.
*
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/sanscript/transliterate.rb', line 129 def transliterate(data, from, to, = {}) from = from.to_sym to = to.to_sym raise "Scheme not known ':#{from}'" unless @schemes.key?(from) raise "Scheme not known ':#{to}'" unless @schemes.key?(to) data = data.to_str.dup = @defaults.merge() map = make_map(from, to) data.gsub!(/(<.*?>)/, "##\\1##") if [:skip_sgml] # Easy way out for "{\m+}", "\", and ".h". if from == :itrans data.gsub!(/\{\\m\+\}/, ".h.N") data.gsub!(/\.h/, "") data.gsub!(/\\([^'`_]|$)/, "##\\1##") end if map[:from_roman?] transliterate_roman(data, map, ) else transliterate_brahmic(data, map) end end |