Module: Yosina::Transliterators::ProlongedSoundMarks::CharType
- Included in:
- Transliterator
- Defined in:
- lib/yosina/transliterators/prolonged_sound_marks.rb
Overview
Mix-in for character type checks
Constant Summary collapse
- HYPHEN_LIKE_CHARS =
Hyphen-like characters that can be converted to prolonged sound marks
[ 0x002d, # HYPHEN-MINUS 0x2010, # HYPHEN 0x2014, # EM DASH 0x2015, # HORIZONTAL BAR 0x2212, # MINUS SIGN 0xff0d, # FULLWIDTH HYPHEN-MINUS 0xff70, # HALFWIDTH KATAKANA-HIRAGANA PROLONGED SOUND MARK (already converted) 0x30fc # KATAKANA-HIRAGANA PROLONGED SOUND MARK (already converted) ].freeze
Instance Method Summary collapse
-
#alphanumeric?(char_code) ⇒ Boolean
Check if character is alphanumeric.
-
#fullwidth?(char_code) ⇒ Boolean
Check if character is fullwidth Japanese.
- #fullwidth_alphanumeric?(char_code) ⇒ Boolean
-
#halfwidth?(char_code) ⇒ Boolean
Check if character is halfwidth Japanese.
- #halfwidth_alphanumeric?(char_code) ⇒ Boolean
- #hatsuon?(char_code) ⇒ Boolean
- #hiragana?(char_code) ⇒ Boolean
- #hyphen_like?(char_code) ⇒ Boolean
- #katakana?(char_code) ⇒ Boolean
- #prolongable?(char_code) ⇒ Boolean
- #prolonged_sound_mark?(char_code) ⇒ Boolean
- #sokuon?(char_code) ⇒ Boolean
Instance Method Details
#alphanumeric?(char_code) ⇒ Boolean
Check if character is alphanumeric
58 59 60 |
# File 'lib/yosina/transliterators/prolonged_sound_marks.rb', line 58 def alphanumeric?(char_code) halfwidth_alphanumeric?(char_code) || fullwidth_alphanumeric?(char_code) end |
#fullwidth?(char_code) ⇒ Boolean
Check if character is fullwidth Japanese
53 54 55 |
# File 'lib/yosina/transliterators/prolonged_sound_marks.rb', line 53 def fullwidth?(char_code) char_code == 0x30fc || hiragana?(char_code) || katakana?(char_code) || fullwidth_alphanumeric?(char_code) end |
#fullwidth_alphanumeric?(char_code) ⇒ Boolean
46 47 48 49 50 |
# File 'lib/yosina/transliterators/prolonged_sound_marks.rb', line 46 def fullwidth_alphanumeric?(char_code) (char_code >= 0xff10 && char_code <= 0xff19) || (char_code >= 0xff21 && char_code <= 0xff3a) || (char_code >= 0xff41 && char_code <= 0xff5a) end |
#halfwidth?(char_code) ⇒ Boolean
Check if character is halfwidth Japanese
22 23 24 25 26 |
# File 'lib/yosina/transliterators/prolonged_sound_marks.rb', line 22 def halfwidth?(char_code) halfwidth_alphanumeric?(char_code) || (char_code >= 0xff66 && char_code <= 0xff6f) || (char_code >= 0xff70 && char_code <= 0xff9f) end |
#halfwidth_alphanumeric?(char_code) ⇒ Boolean
40 41 42 43 44 |
# File 'lib/yosina/transliterators/prolonged_sound_marks.rb', line 40 def halfwidth_alphanumeric?(char_code) (char_code >= 0x30 && char_code <= 0x39) || (char_code >= 0x41 && char_code <= 0x5A) || (char_code >= 0x61 && char_code <= 0x7A) end |
#hatsuon?(char_code) ⇒ Boolean
62 63 64 |
# File 'lib/yosina/transliterators/prolonged_sound_marks.rb', line 62 def hatsuon?(char_code) [0x3093, 0x30f3, 0xff9d].include?(char_code) end |
#hiragana?(char_code) ⇒ Boolean
28 29 30 31 32 |
# File 'lib/yosina/transliterators/prolonged_sound_marks.rb', line 28 def hiragana?(char_code) (char_code >= 0x3041 && char_code <= 0x309c && char_code != 0x3063 && char_code != 0x3093) || char_code == 0x309f end |
#hyphen_like?(char_code) ⇒ Boolean
78 79 80 |
# File 'lib/yosina/transliterators/prolonged_sound_marks.rb', line 78 def hyphen_like?(char_code) HYPHEN_LIKE_CHARS.include?(char_code) end |
#katakana?(char_code) ⇒ Boolean
34 35 36 37 38 |
# File 'lib/yosina/transliterators/prolonged_sound_marks.rb', line 34 def katakana?(char_code) (char_code >= 0x30a1 && char_code <= 0x30fa && char_code != 0x30c3 && char_code != 0x30f3) || (char_code >= 0x30fd && char_code <= 0x30ff) || (char_code >= 0xff70 && char_code <= 0xff9f && char_code != 0xff6f && char_code != 0xff9d) end |
#prolongable?(char_code) ⇒ Boolean
74 75 76 |
# File 'lib/yosina/transliterators/prolonged_sound_marks.rb', line 74 def prolongable?(char_code) prolonged_sound_mark?(char_code) || hiragana?(char_code) || katakana?(char_code) end |
#prolonged_sound_mark?(char_code) ⇒ Boolean
70 71 72 |
# File 'lib/yosina/transliterators/prolonged_sound_marks.rb', line 70 def prolonged_sound_mark?(char_code) [0x30fc, 0xff70].include?(char_code) end |
#sokuon?(char_code) ⇒ Boolean
66 67 68 |
# File 'lib/yosina/transliterators/prolonged_sound_marks.rb', line 66 def sokuon?(char_code) [0x3063, 0x30c3, 0xff6f].include?(char_code) end |