Module: Kanakana

Defined in:
lib/kanakana.rb,
lib/kanakana/version.rb

Overview

Kanakana

Constant Summary collapse

HIRAGANA =

p (“ア”..“ワ”).map{ |c| NKF.nkf(“-Ww –hiragana”, c) }.push(“を”, “ん”) 五十音

%w[
      
      
      
      
      
      
      
    
      
    
].freeze
KATAKANA =
%w[
      
      
      
      
      
      
      
    
      
    
].freeze
DAKUON_HIRAGANA =

DAKUON_BY_HIRAGANA DAKUON_BY_SEION

{
  '' => '', '' => '', '' => '', '' => '', '' => '',
  '' => '', '' => '', '' => '', '' => '', '' => '',
  '' => '', '' => '', '' => '', '' => '', '' => '',
  '' => '', '' => '', '' => '', '' => '', '' => '',
  '' => '', '' => ''
}.freeze
DAKUTENABLE_HIRAGANA =
DAKUON_HIRAGANA.keys
DAKUON_KATAKANA =
{
  '' => '', '' => '', '' => '', '' => '', '' => '',
  '' => '', '' => '', '' => '', '' => '', '' => '',
  '' => '', '' => '', '' => '', '' => '', '' => '',
  '' => '', '' => '', '' => '', '' => '', '' => '',
  '' => '', '' => '',
  '' => '', '' => '', '' => '', '' => ''
}.freeze
DAKUTENABLE_KATAKANA =
DAKUON_KATAKANA.keys
DAKUON_TABLE =
DAKUON_HIRAGANA.merge(DAKUON_KATAKANA)
DAKUTENABLES =
DAKUTENABLE_HIRAGANA + DAKUTENABLE_KATAKANA
HANDAKUON_TABLE =
{
  '' => '', '' => '', '' => '', '' => '', '' => '',
  '' => '', '' => '', '' => '', '' => '', '' => ''
}.freeze
KOGAKI_HIRAGANA =
{
  '' => '', '' => '', '' => '', '' => '', '' => '',
  '' => '', '' => '',
  '' => '',
  '' => '', '' => '', '' => '',
  '' => ''
}.freeze
KOGAKI_KATAKANA =
{
  '' => '', '' => '', '' => '', '' => '', '' => '',
  '' => '', '' => '',
  '' => '',
  '' => '', '' => '', '' => '',
  '' => ''
}.freeze
HIRAGANA_SMALL_LIST =
KOGAKI_HIRAGANA.keys
ITAIJI =
{
  '' => '', '' => '',
  '' => '', '' => '', '' => ''
}.freeze
NOT_DAKUTENABLE_HIRAGANA =
HIRAGANA - DAKUON_HIRAGANA.keys
NOT_DAKUTENABLE_KATAKANA =
KATAKANA - DAKUON_KATAKANA.keys
NOT_DAKUTENABLES =
NOT_DAKUTENABLE_HIRAGANA + NOT_DAKUTENABLE_KATAKANA
VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.escape(str) ⇒ Object



125
126
127
128
# File 'lib/kanakana.rb', line 125

def escape(str)
  # str.unpack('U*').map { |c| "\\u#{c.to_s(16).upcase}" }.join
  str.codepoints.map { |c| "\\u#{c.to_s(16).upcase}" }.join
end

.hiraganize(str) ⇒ Object



103
104
105
# File 'lib/kanakana.rb', line 103

def hiraganize(str)
  NKF.nkf('-w --hiragana', str)
end

.hyper_nigorize(str) ⇒ Object



98
99
100
101
# File 'lib/kanakana.rb', line 98

def hyper_nigorize(str)
  pattern = /([#{NOT_DAKUTENABLES.join}])/
  nigorize(str).gsub(pattern) { "#{Regexp.last_match(1)}\u3099" }
end

.katakanize(str) ⇒ Object



107
108
109
# File 'lib/kanakana.rb', line 107

def katakanize(str)
  NKF.nkf('-w --katakana', str)
end

.make_ascii(str) ⇒ Object



111
112
113
114
115
116
117
118
# File 'lib/kanakana.rb', line 111

def make_ascii(str)
  # NKF.nkf('-m0Z1 -w', str)
  NKF.nkf('-m0Z1 -W -w', str)
  NKF.nkf('-Z1 -Ww', str)
  # str.tr("0-9a-zA-Z.,@−", "0-9a-zA-Z.,@-")
  # str.tr('!-~', '!-~')
  # str.tr(' -~', ' -~')
end

.nigorize(str) ⇒ Object



93
94
95
96
# File 'lib/kanakana.rb', line 93

def nigorize(str)
  pattern = /[#{DAKUTENABLES.join}]/
  str.unicode_normalize.gsub(pattern, DAKUON_TABLE)
end

.ordsObject



130
131
132
# File 'lib/kanakana.rb', line 130

def ords
  str.chars.zip(str.codepoints.map(&:ord)).to_h
end

.table(str) ⇒ Object

charset



135
136
137
# File 'lib/kanakana.rb', line 135

def table(str)
  str.chars.zip(str.codepoints.map { |c| "\\u{#{c.to_s(16).upcase}}" }).to_h
end

.unicodes(str) ⇒ Object



120
121
122
123
# File 'lib/kanakana.rb', line 120

def unicodes(str)
  # str.unpack('U*').map { |c| "U+#{c.to_s(16).upcase}" }
  str.codepoints.map { |c| "U+#{c.to_s(16).upcase}" }
end