Module: Yosina::Transliterators::HiraKata

Includes:
HiraKataTable
Defined in:
lib/yosina/transliterators/hira_kata.rb

Overview

Module for converting between Hiragana and Katakana scripts

Defined Under Namespace

Classes: Transliterator

Constant Summary

Constants included from HiraKataTable

Yosina::Transliterators::HiraKataTable::HIRAGANA_KATAKANA_SMALL_TABLE, Yosina::Transliterators::HiraKataTable::HIRAGANA_KATAKANA_TABLE, Yosina::Transliterators::HiraKataTable::SEMI_VOICED_CHARACTERS, Yosina::Transliterators::HiraKataTable::VOICED_CHARACTERS

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from HiraKataTable

generate_semi_voiced_characters, generate_voiced_characters

Class Attribute Details

.mapping_cacheObject

Returns the value of attribute mapping_cache.



15
16
17
# File 'lib/yosina/transliterators/hira_kata.rb', line 15

def mapping_cache
  @mapping_cache
end

Class Method Details

.build_mapping_table(mode) ⇒ Hash<String, String>

Build the mapping table for the specified mode

Parameters:

  • mode (Symbol)

    :hira_to_kata or :kata_to_hira

Returns:

  • (Hash<String, String>)


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
# File 'lib/yosina/transliterators/hira_kata.rb', line 58

def self.build_mapping_table(mode)
  # Check cache first
  cached = @mapping_cache[mode]
  return cached if cached

  mapping = {}

  # Main table mappings
  HIRAGANA_KATAKANA_TABLE.each do |hiragana_entry, katakana_entry, _|
    next unless hiragana_entry

    hira, hira_voiced, hira_semivoiced = hiragana_entry
    kata, kata_voiced, kata_semivoiced = katakana_entry

    if mode == :hira_to_kata
      mapping[hira] = kata
      mapping[hira_voiced] = kata_voiced if hira_voiced && kata_voiced
      mapping[hira_semivoiced] = kata_semivoiced if hira_semivoiced && kata_semivoiced
    else
      mapping[kata] = hira
      mapping[kata_voiced] = hira_voiced if kata_voiced && hira_voiced
      mapping[kata_semivoiced] = hira_semivoiced if kata_semivoiced && hira_semivoiced
    end
  end

  # Small character mappings
  HIRAGANA_KATAKANA_SMALL_TABLE.each do |hira, kata, _|
    if mode == :hira_to_kata
      mapping[hira] = kata
    else
      mapping[kata] = hira
    end
  end

  # Cache the result
  @mapping_cache[mode] = mapping
  mapping
end

.call(options = {}) ⇒ Transliterator

Factory method to create a hiragana/katakana transliterator

Parameters:

  • options (Hash) (defaults to: {})

    Configuration options

Returns:

  • (Transliterator)

    A new hiragana/katakana transliterator instance



101
102
103
# File 'lib/yosina/transliterators/hira_kata.rb', line 101

def self.call(options = {})
  Transliterator.new(options)
end