Class: Yosina::Transliterators::Jisx0201AndAlike::Transliterator

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

Overview

Transliterator for JIS X 0201 and alike

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Transliterator

Initialize the transliterator with options

Parameters:

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

    Configuration options

Options Hash (options):

  • :fullwidth_to_halfwidth (Boolean)

    Convert fullwidth to halfwidth (default: true)

  • :convert_gl (Boolean)

    Convert GL characters (default: true)

  • :convert_gr (Boolean)

    Convert GR characters (default: true)

  • :convert_unsafe_specials (Boolean)

    Convert unsafe special characters

  • :convert_hiraganas (Boolean)

    Convert hiraganas (default: false)

  • :combine_voiced_sound_marks (Boolean)

    Combine voiced sound marks (default: true)

  • :u005c_as_yen_sign (Boolean)

    Treat backslash as yen sign

  • :u005c_as_backslash (Boolean)

    Treat backslash verbatim

  • :u007e_as_fullwidth_tilde (Boolean)

    Convert tilde to fullwidth tilde

  • :u007e_as_wave_dash (Boolean)

    Convert tilde to wave dash

  • :u007e_as_overline (Boolean)

    Convert tilde to overline

  • :u007e_as_fullwidth_macron (Boolean)

    Convert tilde to fullwidth macron

  • :u00a5_as_yen_sign (Boolean)

    Convert yen sign to backslash



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/yosina/transliterators/jisx0201_and_alike.rb', line 210

def initialize(options = {})
  super()
  @fullwidth_to_halfwidth = options.fetch(:fullwidth_to_halfwidth, true)
  @convert_gl = options.fetch(:convert_gl, true)
  @convert_gr = options.fetch(:convert_gr, true)
  @convert_hiraganas = options.fetch(:convert_hiraganas, false)
  @combine_voiced_sound_marks = options.fetch(:combine_voiced_sound_marks, true)

  # Set defaults based on direction
  if @fullwidth_to_halfwidth
    @convert_unsafe_specials = options.fetch(:convert_unsafe_specials, true)
    @u005c_as_yen_sign = options.fetch(:u005c_as_yen_sign) { !options.key?(:u00a5_as_yen_sign) }
    @u005c_as_backslash = options.fetch(:u005c_as_backslash, false)
    @u007e_as_fullwidth_tilde = options.fetch(:u007e_as_fullwidth_tilde, true)
    @u007e_as_wave_dash = options.fetch(:u007e_as_wave_dash, true)
    @u007e_as_overline = options.fetch(:u007e_as_overline, false)
    @u007e_as_fullwidth_macron = options.fetch(:u007e_as_fullwidth_macron, false)
    @u00a5_as_yen_sign = options.fetch(:u00a5_as_yen_sign, false)
  else
    @convert_unsafe_specials = options.fetch(:convert_unsafe_specials, false)
    @u005c_as_yen_sign = options.fetch(:u005c_as_yen_sign) { !options.key?(:u005c_as_backslash) }
    @u005c_as_backslash = options.fetch(:u005c_as_backslash, false)
    @u007e_as_fullwidth_tilde = options.fetch(:u007e_as_fullwidth_tilde) do
      !options.key?(:u007e_as_wave_dash) &&
        !options.key?(:u007e_as_overline) &&
        !options.key?(:u007e_as_fullwidth_macron)
    end
    @u007e_as_wave_dash = options.fetch(:u007e_as_wave_dash, false)
    @u007e_as_overline = options.fetch(:u007e_as_overline, false)
    @u007e_as_fullwidth_macron = options.fetch(:u007e_as_fullwidth_macron, false)
    @u00a5_as_yen_sign = options.fetch(:u00a5_as_yen_sign, true)
  end

  validate_options!
  build_mappings!
end

Instance Attribute Details

#combine_voiced_sound_marksObject (readonly)

Returns the value of attribute combine_voiced_sound_marks.



187
188
189
# File 'lib/yosina/transliterators/jisx0201_and_alike.rb', line 187

def combine_voiced_sound_marks
  @combine_voiced_sound_marks
end

#convert_glObject (readonly)

Returns the value of attribute convert_gl.



187
188
189
# File 'lib/yosina/transliterators/jisx0201_and_alike.rb', line 187

def convert_gl
  @convert_gl
end

#convert_grObject (readonly)

Returns the value of attribute convert_gr.



187
188
189
# File 'lib/yosina/transliterators/jisx0201_and_alike.rb', line 187

def convert_gr
  @convert_gr
end

#convert_hiraganasObject (readonly)

Returns the value of attribute convert_hiraganas.



187
188
189
# File 'lib/yosina/transliterators/jisx0201_and_alike.rb', line 187

def convert_hiraganas
  @convert_hiraganas
end

#convert_unsafe_specialsObject (readonly)

Returns the value of attribute convert_unsafe_specials.



187
188
189
# File 'lib/yosina/transliterators/jisx0201_and_alike.rb', line 187

def convert_unsafe_specials
  @convert_unsafe_specials
end

#fullwidth_to_halfwidthObject (readonly)

Returns the value of attribute fullwidth_to_halfwidth.



187
188
189
# File 'lib/yosina/transliterators/jisx0201_and_alike.rb', line 187

def fullwidth_to_halfwidth
  @fullwidth_to_halfwidth
end

#u005c_as_backslashObject (readonly)

Returns the value of attribute u005c_as_backslash.



187
188
189
# File 'lib/yosina/transliterators/jisx0201_and_alike.rb', line 187

def u005c_as_backslash
  @u005c_as_backslash
end

#u005c_as_yen_signObject (readonly)

Returns the value of attribute u005c_as_yen_sign.



187
188
189
# File 'lib/yosina/transliterators/jisx0201_and_alike.rb', line 187

def u005c_as_yen_sign
  @u005c_as_yen_sign
end

#u007e_as_fullwidth_macronObject (readonly)

Returns the value of attribute u007e_as_fullwidth_macron.



187
188
189
# File 'lib/yosina/transliterators/jisx0201_and_alike.rb', line 187

def u007e_as_fullwidth_macron
  @u007e_as_fullwidth_macron
end

#u007e_as_fullwidth_tildeObject (readonly)

Returns the value of attribute u007e_as_fullwidth_tilde.



187
188
189
# File 'lib/yosina/transliterators/jisx0201_and_alike.rb', line 187

def u007e_as_fullwidth_tilde
  @u007e_as_fullwidth_tilde
end

#u007e_as_overlineObject (readonly)

Returns the value of attribute u007e_as_overline.



187
188
189
# File 'lib/yosina/transliterators/jisx0201_and_alike.rb', line 187

def u007e_as_overline
  @u007e_as_overline
end

#u007e_as_wave_dashObject (readonly)

Returns the value of attribute u007e_as_wave_dash.



187
188
189
# File 'lib/yosina/transliterators/jisx0201_and_alike.rb', line 187

def u007e_as_wave_dash
  @u007e_as_wave_dash
end

#u00a5_as_yen_signObject (readonly)

Returns the value of attribute u00a5_as_yen_sign.



187
188
189
# File 'lib/yosina/transliterators/jisx0201_and_alike.rb', line 187

def u00a5_as_yen_sign
  @u00a5_as_yen_sign
end

Instance Method Details

#call(input_chars) ⇒ Enumerable<Char>

Transliterate characters

Parameters:

  • input_chars (Enumerable<Char>)

    The characters to transliterate

Returns:

  • (Enumerable<Char>)

    The transliterated characters



251
252
253
254
255
256
257
# File 'lib/yosina/transliterators/jisx0201_and_alike.rb', line 251

def call(input_chars)
  if @fullwidth_to_halfwidth
    convert_fullwidth_to_halfwidth(input_chars)
  else
    convert_halfwidth_to_fullwidth(input_chars)
  end
end