Module: Sanscript::Detect
- Defined in:
- lib/sanscript/detect.rb
Overview
Transliteration scheme detection module. Developed from code available @ github.com/sanskrit/detect.js
Class Method Summary collapse
-
.detect_scheme(text) ⇒ Symbol?
Attempts to detect the encoding scheme of the provided string.
Class Method Details
.detect_scheme(text) ⇒ Symbol?
Attempts to detect the encoding scheme of the provided string.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/sanscript/detect.rb', line 60 def detect_scheme(text) text = text.to_str.gsub(RE_CONTROL_BLOCK, "") # Brahmic schemes are all within a specific range of code points. if RE_BRAHMIC_RANGE === text RE_BRAHMIC_SCRIPTS.each do |script, regex| return script if regex === text end end # Romanizations if RE_IAST_OR_KOLKATA_ONLY === text return :kolkata if RE_KOLKATA_ONLY === text :iast elsif RE_ITRANS_ONLY === text :itrans elsif RE_SLP1_ONLY === text :slp1 elsif RE_VELTHUIS_ONLY === text :velthuis elsif RE_ITRANS_OR_VELTHUIS_ONLY === text :itrans elsif RE_HARVARD_KYOTO === text :hk end end |