Module: Sanscript::Detect

Defined in:
lib/sanscript/detect.rb

Class Method Summary collapse

Class Method Details

.detect_script(text) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/sanscript/detect.rb', line 53

def detect_script(text)
  text = text.to_str.gsub(/(?<!\\)##.*?(?<!\\)##|(?<!\\)\{#.*?(?<!\\)#\}/, "")

  # 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
  else
    :unknown
  end
end