Module: Iudex::Core::MojiBake

Defined in:
lib/iudex-core/mojibake.rb

Constant Summary collapse

DEFAULT_CONFIG =
File.join( File.dirname( __FILE__ ),
'..', '..', 'config', 'mojibake' )

Class Method Summary collapse

Class Method Details

.load_config(file = DEFAULT_CONFIG) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/iudex-core/mojibake.rb', line 26

def self.load_config( file = DEFAULT_CONFIG )
  regex = nil
  mojis = []
  File.open( file ) do |fin|
    fin.each do |line|
      case line
      when %r{^/([^/]+)/$}
        regex = $1
      when /^\[.*?\]\s+([0-9A-F ]+)\s+\[.*\]\s+([0-9A-F]+)$/
        mojis << [ $1.split( ' ' ), $2 ]
      end
    end
  end

  mh = Java::java.util.HashMap.new( 512 )
  mojis.each do | moji, rpl |
    mh.put( jstring( moji ), jstring( rpl ) )
  end
  [ regex, mh ]
end