japanese_char_real 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +47 -0
- data/Rakefile +2 -0
- data/japanese_char_real.gemspec +23 -0
- data/lib/japanese_char_real.rb +64 -0
- data/lib/japanese_char_real/version.rb +3 -0
- data/spec/japanese_char_real_spec.rb +20 -0
- data/spec/spec_helper.rb +76 -0
- metadata +88 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0f75ff7f1a07550c56f4e147bbeab4ce8c1dd7a7
|
4
|
+
data.tar.gz: e0b993ae556c993807151e200c9cf45cfd40826c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4e30e902fb7808b61956cde70a88a1daeac72c0023b434d017321286f5b50edd84a56d95c487222bf36f8fe40319598aaf406a9ae018af754076f75182f6624a
|
7
|
+
data.tar.gz: 7462a5f926ea252277966fd072a639503d900eb579dca9e4875c92544a6520ead431bfcd5e039dcf84f0e2f5db518a86b5931abf2dd83064129d8e374931b6cd
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 linyows
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
Japanese Char Real
|
2
|
+
==================
|
3
|
+
|
4
|
+
ujisのデータベースとutf-8のアプリケーション環境で発生する文字化けを`一部`解消する
|
5
|
+
|
6
|
+
[![Gem Version](https://badge.fury.io/rb/japanese_char_real.svg)][gem]
|
7
|
+
[![Build Status](https://travis-ci.org/pepabo/japanese_char_real.svg?branch=master)][travis]
|
8
|
+
|
9
|
+
[gem]: https://rubygems.org/gems/japanese_char_real
|
10
|
+
[travis]: http://travis-ci.org/linyows/japanese_char_real
|
11
|
+
|
12
|
+
Installation
|
13
|
+
------------
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'japanese_char_real'
|
19
|
+
```
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
$ gem install japanese_char_real
|
28
|
+
|
29
|
+
Usage
|
30
|
+
-----
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
::String.__send__ :include, JapaneseCharReal::String
|
34
|
+
User.name
|
35
|
+
#=> 山 太郎
|
36
|
+
User.name.to_real
|
37
|
+
#=> 山﨑 太郎
|
38
|
+
```
|
39
|
+
|
40
|
+
Contributing
|
41
|
+
------------
|
42
|
+
|
43
|
+
1. Fork it ( https://github.com/pepabo/japanese_char_real/fork )
|
44
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
45
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
46
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
47
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'japanese_char_real/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "japanese_char_real"
|
8
|
+
spec.version = JapaneseCharReal::VERSION
|
9
|
+
spec.authors = ["linyows"]
|
10
|
+
spec.email = ["linyows@gmail.com"]
|
11
|
+
spec.summary = %q{This is to eliminate thenly some garbledccur by using the ujis database with UTF-8 applications}
|
12
|
+
spec.description = %q{This is to eliminate thenly some garbledccur by using the ujis database with UTF-8 applications}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module JapaneseCharReal
|
4
|
+
class << self
|
5
|
+
def utf8_failure
|
6
|
+
{
|
7
|
+
'8ff3a1' => 'ⅰ',
|
8
|
+
'8ff3a2' => 'ⅱ',
|
9
|
+
'8ff3a3' => 'ⅲ',
|
10
|
+
'8ff3a4' => 'ⅳ',
|
11
|
+
'8ff3a5' => 'ⅴ',
|
12
|
+
'8ff3a5' => 'ⅵ',
|
13
|
+
'8ff3a7' => 'ⅶ',
|
14
|
+
'8ff3a8' => 'ⅷ',
|
15
|
+
'8ff3a9' => 'ⅸ',
|
16
|
+
'8ff3aa' => 'ⅹ',
|
17
|
+
'8ff3ab' => 'Ⅰ',
|
18
|
+
'8ff3ac' => 'Ⅱ',
|
19
|
+
'8ff3ad' => 'Ⅲ',
|
20
|
+
'8ff3ae' => 'Ⅳ',
|
21
|
+
'8ff3af' => 'Ⅴ',
|
22
|
+
'8ff3b0' => 'Ⅵ',
|
23
|
+
'8ff3b1' => 'Ⅶ',
|
24
|
+
'8ff3b2' => 'Ⅷ',
|
25
|
+
'8ff3b3' => 'Ⅸ',
|
26
|
+
'8ff3b4' => 'Ⅹ',
|
27
|
+
'8ff3b7' => '㈱'
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def gaiji_to_utf8
|
32
|
+
{
|
33
|
+
'ee8b93' => '髙',
|
34
|
+
'ee878c' => '﨑'
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
def convert(str, encode: :ujis_to_utf8)
|
39
|
+
return str if str.ascii_only?
|
40
|
+
|
41
|
+
case encode
|
42
|
+
when :ujis_to_utf8
|
43
|
+
unless str.encoding.name == 'UTF-8'
|
44
|
+
str.encode!(Encoding::UTF_8, fallback: -> c {
|
45
|
+
self.utf8_failure[c.unpack('H*').first] || '?'
|
46
|
+
})
|
47
|
+
end
|
48
|
+
str.split('').map { |c|
|
49
|
+
self.gaiji_to_utf8[c.unpack('H*').first] || c
|
50
|
+
}.join('')
|
51
|
+
|
52
|
+
when :utf8_to_ujis
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# usage:
|
58
|
+
# ::String.__send__ :include, JapaneseCharReal::String
|
59
|
+
module String
|
60
|
+
def to_real(encode: :ujis_to_utf8)
|
61
|
+
JapaneseCharReal.convert(self, encode: encode)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe JapaneseCharReal do
|
6
|
+
describe 'String.to_real' do
|
7
|
+
context 'when include gaiji' do
|
8
|
+
it 'returns real string' do
|
9
|
+
expect('山 太郎'.to_real).to eq'山﨑 太郎'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'when string is euc-jp' do
|
14
|
+
it 'returns real string' do
|
15
|
+
str = ['8ff3ac'].pack('H*').force_encoding('EUC-JP')
|
16
|
+
expect(str.to_real).to eq 'Ⅱ'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'japanese_char_real'
|
2
|
+
::String.__send__ :include, JapaneseCharReal::String
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
# rspec-expectations config goes here. You can use an alternate
|
6
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
7
|
+
# assertions if you prefer.
|
8
|
+
config.expect_with :rspec do |expectations|
|
9
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
10
|
+
# and `failure_message` of custom matchers include text for helper methods
|
11
|
+
# defined using `chain`, e.g.:
|
12
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
13
|
+
# # => "be bigger than 2 and smaller than 4"
|
14
|
+
# ...rather than:
|
15
|
+
# # => "be bigger than 2"
|
16
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
17
|
+
end
|
18
|
+
|
19
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
20
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
21
|
+
config.mock_with :rspec do |mocks|
|
22
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
23
|
+
# a real object. This is generally recommended, and will default to
|
24
|
+
# `true` in RSpec 4.
|
25
|
+
mocks.verify_partial_doubles = true
|
26
|
+
end
|
27
|
+
|
28
|
+
# The settings below are suggested to provide a good initial experience
|
29
|
+
# with RSpec, but feel free to customize to your heart's content.
|
30
|
+
=begin
|
31
|
+
# These two settings work together to allow you to limit a spec run
|
32
|
+
# to individual examples or groups you care about by tagging them with
|
33
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
34
|
+
# get run.
|
35
|
+
config.filter_run :focus
|
36
|
+
config.run_all_when_everything_filtered = true
|
37
|
+
|
38
|
+
# Limits the available syntax to the non-monkey patched syntax that is recommended.
|
39
|
+
# For more details, see:
|
40
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
41
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
42
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
43
|
+
config.disable_monkey_patching!
|
44
|
+
|
45
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
46
|
+
# be too noisy due to issues in dependencies.
|
47
|
+
config.warnings = true
|
48
|
+
|
49
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
50
|
+
# file, and it's useful to allow more verbose output when running an
|
51
|
+
# individual spec file.
|
52
|
+
if config.files_to_run.one?
|
53
|
+
# Use the documentation formatter for detailed output,
|
54
|
+
# unless a formatter has already been configured
|
55
|
+
# (e.g. via a command-line flag).
|
56
|
+
config.default_formatter = 'doc'
|
57
|
+
end
|
58
|
+
|
59
|
+
# Print the 10 slowest examples and example groups at the
|
60
|
+
# end of the spec run, to help surface which specs are running
|
61
|
+
# particularly slow.
|
62
|
+
config.profile_examples = 10
|
63
|
+
|
64
|
+
# Run specs in random order to surface order dependencies. If you find an
|
65
|
+
# order dependency and want to debug it, you can fix the order by providing
|
66
|
+
# the seed, which is printed after each run.
|
67
|
+
# --seed 1234
|
68
|
+
config.order = :random
|
69
|
+
|
70
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
71
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
72
|
+
# test failures related to randomization by passing the same `--seed` value
|
73
|
+
# as the one that triggered the failure.
|
74
|
+
Kernel.srand config.seed
|
75
|
+
=end
|
76
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: japanese_char_real
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- linyows
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: This is to eliminate thenly some garbledccur by using the ujis database
|
42
|
+
with UTF-8 applications
|
43
|
+
email:
|
44
|
+
- linyows@gmail.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- ".rspec"
|
51
|
+
- ".travis.yml"
|
52
|
+
- Gemfile
|
53
|
+
- LICENSE.txt
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- japanese_char_real.gemspec
|
57
|
+
- lib/japanese_char_real.rb
|
58
|
+
- lib/japanese_char_real/version.rb
|
59
|
+
- spec/japanese_char_real_spec.rb
|
60
|
+
- spec/spec_helper.rb
|
61
|
+
homepage: ''
|
62
|
+
licenses:
|
63
|
+
- MIT
|
64
|
+
metadata: {}
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 2.2.2
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: This is to eliminate thenly some garbledccur by using the ujis database with
|
85
|
+
UTF-8 applications
|
86
|
+
test_files:
|
87
|
+
- spec/japanese_char_real_spec.rb
|
88
|
+
- spec/spec_helper.rb
|