Class: Yosina::Transliterators::HistoricalHirakatas::Transliterator
- Inherits:
-
BaseTransliterator
- Object
- BaseTransliterator
- Yosina::Transliterators::HistoricalHirakatas::Transliterator
- Defined in:
- lib/yosina/transliterators/historical_hirakatas.rb
Overview
Transliterator for historical hiragana/katakana conversion
Instance Method Summary collapse
-
#call(input_chars) ⇒ Enumerable<Char>
Convert historical hiragana/katakana characters to modern equivalents.
-
#initialize(options = {}) ⇒ Transliterator
constructor
Initialize the transliterator with options.
Constructor Details
#initialize(options = {}) ⇒ Transliterator
Initialize the transliterator with options
46 47 48 49 50 51 |
# File 'lib/yosina/transliterators/historical_hirakatas.rb', line 46 def initialize( = {}) super() @hiraganas = ([:hiraganas] || :simple).to_sym @katakanas = ([:katakanas] || :simple).to_sym @voiced_katakanas = ([:voiced_katakanas] || :skip).to_sym end |
Instance Method Details
#call(input_chars) ⇒ Enumerable<Char>
Convert historical hiragana/katakana characters to modern equivalents
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/yosina/transliterators/historical_hirakatas.rb', line 57 def call(input_chars) Chars.enum do |y| offset = 0 pending = nil input_chars.each do |char| if char.sentinel? offset = emit_char(y, pending, offset) if pending pending = nil y << char break end if pending.nil? pending = char next end if char.c == COMBINING_DAKUTEN # Check if pending char could be a decomposed voiced base decomposed = VOICED_HISTORICAL_KANA_DECOMPOSED_MAPPINGS[pending.c] if @voiced_katakanas == :skip || decomposed.nil? y << pending.with_offset(offset) offset += pending.c.length pending = char next end y << Char.new(c: U, offset: offset, source: pending) offset += U.length y << char.with_offset(offset) offset += char.c.length y << Char.new(c: decomposed, offset: offset, source: pending) offset += decomposed.length pending = nil next end offset = emit_char(y, pending, offset) pending = char end # Flush any remaining pending char emit_char(y, pending, offset) if pending end end |