class String

Public Instance Methods

chinese?() click to toggle source

Returns true if the string contains Chinese characters and no Japanese or Korean characters

# File lib/script_detector.rb, line 9
def chinese?
  look_for_chars_in(/\p{Han}/) and !self.japanese? and !self.korean?
end
identify_script() click to toggle source

Try to detect script and return one of “Japanese”, “Korean”, “Traditional Chinese”, “Simplified Chinese”, “Ambiguous Chinese” or “Unknown”

# File lib/script_detector.rb, line 34
def identify_script
  return "Japanese" if self.japanese?
  return "Korean" if self.korean?
  return "Traditional Chinese" if self.traditional_chinese?
  return "Simplified Chinese" if self.simplified_chinese?
  return "Ambiguous Chinese" if self.chinese?
  "Unknown"
end
japanese?() click to toggle source

Returns true if the string contains specifically Japanese (hiragana or katakana) characters

# File lib/script_detector.rb, line 24
def japanese?
  look_for_chars_in /(\p{Katakana}|\p{Hiragana})/
end
korean?() click to toggle source

Returns true if the string contains specifically Korean (hangul) characters

# File lib/script_detector.rb, line 29
def korean?
  look_for_chars_in /\p{Hangul}/
end
simplified_chinese?() click to toggle source

Return true if the string contains simplified Chinese characters (简体字)

# File lib/script_detector.rb, line 19
def simplified_chinese?
  look_for_chars_in simplified_chinese_regex
end
traditional_chinese?() click to toggle source

Return true if the string contains traditional Chinese characters (繁體字)

# File lib/script_detector.rb, line 14
def traditional_chinese?
  look_for_chars_in traditional_chinese_regex
end

Private Instance Methods

look_for_chars_in(regex) click to toggle source
# File lib/script_detector.rb, line 45
def look_for_chars_in regex
  !! (self =~ regex)
end