Sha256: 13ce6f6d98831f12d267be1b790fe7a7e86d2d6ac9af06a30f679aa3ba6ac85a

Contents?: true

Size: 844 Bytes

Versions: 2

Compression:

Stored size: 844 Bytes

Contents

$KCODE = 'U'

module Gimchi
class Korean
  # Checks if the given character is a korean character.
  # @param [String] ch A string of size 1
  def korean_char? ch
    raise ArgumentError.new('Lengthy input') if str_length(ch) > 1

    complete_korean_char?(ch) || 
      (chosungs + jungsungs + jongsungs).include?(ch)
  end

  # Checks if the given character is a "complete" korean character.
  # "Complete" Korean character must have chosung and jungsung, with optional jongsung.
  # @param [String] ch A string of size 1
  def complete_korean_char? ch
    raise ArgumentError.new('Lengthy input') if str_length(ch) > 1

    # Range of Korean chracters in Unicode 2.0: AC00(가) ~ D7A3(힣)
    ch.unpack('U').all? { | c | c >= 0xAC00 && c <= 0xD7A3 }
  end

private
  def str_length str
    str.scan(/./mu).length
  end
end#Korean
end#Gimchi

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gimchi-0.1.8 lib/gimchi/patch_1.8.rb
gimchi-0.1.7 lib/gimchi/patch_1.8.rb