Class: UnihanLang::Unihan

Inherits:
Object
  • Object
show all
Defined in:
lib/unihan_lang.rb

Instance Method Summary collapse

Constructor Details

#initializeUnihan

Returns a new instance of Unihan.



8
9
10
# File 'lib/unihan_lang.rb', line 8

def initialize
  @chinese_processor = ChineseProcessor.new
end

Instance Method Details

#contains_chinese?(text) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/unihan_lang.rb', line 36

def contains_chinese?(text)
  text.chars.any? { |char| @chinese_processor.chinese_character?(char) }
end

#contains_zh_cn?(text) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/unihan_lang.rb', line 32

def contains_zh_cn?(text)
  text.chars.any? { |char| @chinese_processor.only_zh_cn?(char) }
end

#contains_zh_tw?(text) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/unihan_lang.rb', line 28

def contains_zh_tw?(text)
  text.chars.any? { |char| @chinese_processor.only_zh_tw?(char) }
end

#determine_language(text) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/unihan_lang.rb', line 44

def determine_language(text)
  case language_ratio(text)
  when :tw then "ZH_TW"
  when :cn then "ZH_CN"
  else "Unknown"
  end
end

#extract_chinese_characters(text) ⇒ Object



40
41
42
# File 'lib/unihan_lang.rb', line 40

def extract_chinese_characters(text)
  text.chars.select { |char| @chinese_processor.chinese_character?(char) }
end

#only_zh_cn?(text) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/unihan_lang.rb', line 24

def only_zh_cn?(text)
  text.chars.all? { |char| @chinese_processor.only_zh_cn?(char) }
end

#only_zh_tw?(text) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/unihan_lang.rb', line 20

def only_zh_tw?(text)
  text.chars.all? { |char| @chinese_processor.only_zh_tw?(char) }
end

#zh_cn?(text) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/unihan_lang.rb', line 16

def zh_cn?(text)
  language_ratio(text) == :cn
end

#zh_tw?(text) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/unihan_lang.rb', line 12

def zh_tw?(text)
  language_ratio(text) == :tw
end