Module: Yosina::Transliterators::JapaneseIterationMarks::CharType
- Included in:
- Transliterator
- Defined in:
- lib/yosina/transliterators/japanese_iteration_marks.rb
Overview
Mix-in for character type checks
Instance Method Summary collapse
-
#hatsuon?(char_code) ⇒ Boolean
Check if character is hatsuon (ん/ン).
-
#hiragana?(char_code) ⇒ Boolean
Check if character is hiragana (excluding small forms and special marks).
-
#iteration_mark?(char) ⇒ Boolean
Check if character is an iteration mark.
-
#kanji?(char_code) ⇒ Boolean
Check if character is kanji.
-
#katakana?(char_code) ⇒ Boolean
Check if character is katakana (including halfwidth).
-
#semi_voiced?(char) ⇒ Boolean
Check if character is semi-voiced (has handakuten).
-
#sokuon?(char_code) ⇒ Boolean
Check if character is sokuon (っ/ッ).
-
#voiced?(char) ⇒ Boolean
Check if character is voiced (has dakuten).
Instance Method Details
#hatsuon?(char_code) ⇒ Boolean
Check if character is hatsuon (ん/ン)
45 46 47 |
# File 'lib/yosina/transliterators/japanese_iteration_marks.rb', line 45 def hatsuon?(char_code) [0x3093, 0x30f3, 0xff9d].include?(char_code) end |
#hiragana?(char_code) ⇒ Boolean
Check if character is hiragana (excluding small forms and special marks)
21 22 23 |
# File 'lib/yosina/transliterators/japanese_iteration_marks.rb', line 21 def hiragana?(char_code) char_code >= 0x3041 && char_code <= 0x3096 end |
#iteration_mark?(char) ⇒ Boolean
Check if character is an iteration mark
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/yosina/transliterators/japanese_iteration_marks.rb', line 55 def iteration_mark?(char) [ HIRAGANA_ITERATION_MARK, HIRAGANA_VOICED_ITERATION_MARK, VERTICAL_HIRAGANA_ITERATION_MARK, VERTICAL_HIRAGANA_VOICED_ITERATION_MARK, KATAKANA_ITERATION_MARK, KATAKANA_VOICED_ITERATION_MARK, VERTICAL_KATAKANA_ITERATION_MARK, VERTICAL_KATAKANA_VOICED_ITERATION_MARK, KANJI_ITERATION_MARK ].include?(char) end |
#kanji?(char_code) ⇒ Boolean
Check if character is kanji
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/yosina/transliterators/japanese_iteration_marks.rb', line 32 def kanji?(char_code) # CJK Unified Ideographs (common kanji ranges) (char_code >= 0x4e00 && char_code <= 0x9fff) || (char_code >= 0x3400 && char_code <= 0x4dbf) || (char_code >= 0x20000 && char_code <= 0x2a6df) || (char_code >= 0x2a700 && char_code <= 0x2b73f) || (char_code >= 0x2b740 && char_code <= 0x2b81f) || (char_code >= 0x2b820 && char_code <= 0x2ceaf) || (char_code >= 0x2ceb0 && char_code <= 0x2ebef) || (char_code >= 0x30000 && char_code <= 0x3134f) end |
#katakana?(char_code) ⇒ Boolean
Check if character is katakana (including halfwidth)
26 27 28 29 |
# File 'lib/yosina/transliterators/japanese_iteration_marks.rb', line 26 def katakana?(char_code) (char_code >= 0x30a1 && char_code <= 0x30fa) || (char_code >= 0xff66 && char_code <= 0xff9f) end |
#semi_voiced?(char) ⇒ Boolean
Check if character is semi-voiced (has handakuten)
75 76 77 78 79 80 |
# File 'lib/yosina/transliterators/japanese_iteration_marks.rb', line 75 def semi_voiced?(char) # Hiragana semi-voiced %w[ぱ ぴ ぷ ぺ ぽ].include?(char) || # Katakana semi-voiced %w[パ ピ プ ペ ポ].include?(char) end |
#sokuon?(char_code) ⇒ Boolean
Check if character is sokuon (っ/ッ)
50 51 52 |
# File 'lib/yosina/transliterators/japanese_iteration_marks.rb', line 50 def sokuon?(char_code) [0x3063, 0x30c3, 0xff6f].include?(char_code) end |
#voiced?(char) ⇒ Boolean
Check if character is voiced (has dakuten)
70 71 72 |
# File 'lib/yosina/transliterators/japanese_iteration_marks.rb', line 70 def voiced?(char) VOICED_CHARS.include?(char) end |