Class: Yosina::Transliterators::Hyphens::Transliterator
- Inherits:
-
BaseTransliterator
- Object
- BaseTransliterator
- Yosina::Transliterators::Hyphens::Transliterator
- Defined in:
- lib/yosina/transliterators/hyphens.rb
Overview
Transliterator for hyphens
Instance Attribute Summary collapse
-
#precedence ⇒ Object
readonly
Returns the value of attribute precedence.
Instance Method Summary collapse
-
#call(input_chars) ⇒ Enumerable<Char>
Normalize hyphen characters based on precedence.
-
#initialize(options = nil) ⇒ Transliterator
constructor
Initialize the transliterator with options.
Constructor Details
#initialize(options = nil) ⇒ Transliterator
Initialize the transliterator with options
24 25 26 27 |
# File 'lib/yosina/transliterators/hyphens.rb', line 24 def initialize( = nil) super() @precedence = [:precedence] || DEFAULT_PRECEDENCE end |
Instance Attribute Details
#precedence ⇒ Object (readonly)
Returns the value of attribute precedence.
16 17 18 |
# File 'lib/yosina/transliterators/hyphens.rb', line 16 def precedence @precedence end |
Instance Method Details
#call(input_chars) ⇒ Enumerable<Char>
Normalize hyphen characters based on precedence
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/yosina/transliterators/hyphens.rb', line 33 def call(input_chars) offset = 0 Chars.enum do |y| input_chars.each do |char| record = HyphensData::HYPHENS_MAPPINGS[char.c] if record replacement = get_replacement(record) if replacement && replacement != char.c replacement.each_char do |c| y << Char.new(c: c, offset: offset, source: char) offset += replacement.length end else y << Char.new(c: char.c, offset: offset, source: char) offset += char.c.length end else y << Char.new(c: char.c, offset: offset, source: char) offset += char.c.length end end end end |