Module: MojiBake::JSONSupport
Constant Summary
collapse
- JSON_CONFIG =
File.join( File.dirname( __FILE__ ),
'..', '..', 'config', 'table.json' )
Instance Method Summary
collapse
#jruby_version_a, #ruby_version_a, #ver_to_a
Instance Method Details
#config ⇒ Object
32
33
34
|
# File 'lib/mojibake/json.rb', line 32
def config
@config ||= JSON.parse( IO.read( JSON_CONFIG ) )
end
|
#create_regexp ⇒ Object
44
45
46
47
48
|
# File 'lib/mojibake/json.rb', line 44
def create_regexp
lang = ( ruby_version_a <=> [1,9] ) >= 0 ? nil : 'U'
Regexp.new( config[ 'regexp' ], 0, lang )
end
|
#hash ⇒ Object
36
37
38
|
# File 'lib/mojibake/json.rb', line 36
def hash
@hash ||= config[ 'moji' ]
end
|
#hash_to_json_object ⇒ Object
table as self contained json-ready Hash
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/mojibake/json.rb', line 51
def hash_to_json_object
moji = hash.sort.map do |kv|
kv.map do |s|
s.codepoints.inject( '' ) do |r,i|
if MojiBake::Mapper::INTEREST_CODEPOINTS.include?( i )
r << sprintf( '\u%04X', i )
else
r << i.chr( Encoding::UTF_8 )
end
end
end
end
{ :mojibake => MojiBake::VERSION,
:url => "https://github.com/dekellum/mojibake",
:regexp => regexp.inspect[1...-1],
:moji => Hash[ moji ] }
end
|
#initialize ⇒ Object
28
29
30
|
# File 'lib/mojibake/json.rb', line 28
def initialize
super
end
|
#json ⇒ Object
Pretty formatted JSON serialized String for json_object
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/mojibake/json.rb', line 74
def json
JSON.pretty_generate( hash_to_json_object ).gsub( /\\\\u/, '\u' )
end
|
#regexp ⇒ Object
40
41
42
|
# File 'lib/mojibake/json.rb', line 40
def regexp
@regexp ||= create_regexp
end
|