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.
-
.brahmic_schemes ⇒ Object
readonly
Returns the value of attribute brahmic_schemes.
-
.defaults ⇒ Object
readonly
Returns the value of attribute defaults.
-
.roman_schemes ⇒ Object
readonly
Returns the value of attribute roman_schemes.
-
.scheme_names ⇒ Object
readonly
Returns the value of attribute scheme_names.
-
.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.
-
.brahmic_scheme?(name) ⇒ Boolean
Check whether the given scheme encodes Brahmic Sanskrit.
-
.roman_scheme?(name) ⇒ Boolean
Check whether the given scheme encodes romanized Sanskrit.
-
.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 |
.brahmic_schemes ⇒ Object (readonly)
Returns the value of attribute brahmic_schemes.
17 18 19 |
# File 'lib/sanscript/transliterate.rb', line 17 def brahmic_schemes @brahmic_schemes 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 |
.scheme_names ⇒ Object (readonly)
Returns the value of attribute scheme_names.
17 18 19 |
# File 'lib/sanscript/transliterate.rb', line 17 def scheme_names @scheme_names 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.
68 69 70 71 72 73 74 75 |
# File 'lib/sanscript/transliterate.rb', line 68 def add_brahmic_scheme(name, scheme) name = name.to_sym scheme = scheme.deep_dup @schemes[name] = scheme.deep_freeze @brahmic_schemes.add(name) @scheme_names.add(name) scheme 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.
86 87 88 89 90 91 92 93 94 |
# File 'lib/sanscript/transliterate.rb', line 86 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) @scheme_names.add(name) scheme end |
.brahmic_scheme?(name) ⇒ Boolean
Check whether the given scheme encodes Brahmic Sanskrit.
@param name the scheme name
@return boolean
36 37 38 |
# File 'lib/sanscript/transliterate.rb', line 36 def brahmic_scheme?(name) @brahmic_schemes.include?(name.to_sym) end |
.roman_scheme?(name) ⇒ Boolean
Check whether the given scheme encodes romanized Sanskrit.
@param name the scheme name
@return boolean
46 47 48 |
# File 'lib/sanscript/transliterate.rb', line 46 def roman_scheme?(name) @roman_schemes.include?(name.to_sym) end |
.transliterate(data, from, to, options = {}) ⇒ Object
/** Transliterate from one script to another.
*
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/sanscript/transliterate.rb', line 148 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 |