Class: UnihanLang::Unihan
- Inherits:
-
Object
- Object
- UnihanLang::Unihan
- Defined in:
- lib/unihan_lang.rb
Instance Method Summary collapse
- #contains_chinese?(text) ⇒ Boolean
- #contains_zh_cn?(text) ⇒ Boolean
- #contains_zh_tw?(text) ⇒ Boolean
- #determine_language(text) ⇒ Object
- #extract_chinese_characters(text) ⇒ Object
-
#initialize ⇒ Unihan
constructor
A new instance of Unihan.
- #only_zh_cn?(text) ⇒ Boolean
- #only_zh_tw?(text) ⇒ Boolean
- #zh_cn?(text) ⇒ Boolean
- #zh_tw?(text) ⇒ Boolean
Constructor Details
#initialize ⇒ Unihan
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
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
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
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
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
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
16 17 18 |
# File 'lib/unihan_lang.rb', line 16 def zh_cn?(text) language_ratio(text) == :cn end |
#zh_tw?(text) ⇒ Boolean
12 13 14 |
# File 'lib/unihan_lang.rb', line 12 def zh_tw?(text) language_ratio(text) == :tw end |