Class: Yosina::Transliterators::Hyphens::Transliterator

Inherits:
BaseTransliterator show all
Defined in:
lib/yosina/transliterators/hyphens.rb

Overview

Transliterator for hyphens

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = nil) ⇒ Transliterator

Initialize the transliterator with options

Parameters:

  • options (Hash) (defaults to: nil)

    Configuration options

Options Hash (options):

  • :precedence (Array<Symbol>)

    List of mapping variants to apply in order. Available options: :ascii, :jisx0201, :jisx0208_90, :jisx0208_90_windows, :jisx0208_verbatim Defaults to [:jisx0208_90]



24
25
26
27
# File 'lib/yosina/transliterators/hyphens.rb', line 24

def initialize(options = nil)
  super()
  @precedence = options[:precedence] || DEFAULT_PRECEDENCE
end

Instance Attribute Details

#precedenceObject (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

Parameters:

  • input_chars (Enumerable<Char>)

    The characters to transliterate

Returns:

  • (Enumerable<Char>)

    The transliterated characters



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