encx 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/README.md +39 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/encx.gemspec +30 -0
- data/exe/encx +3 -0
- data/lib/encx.rb +123 -0
- data/lib/encx/version.rb +3 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 60a2d135714ab1d0a163c43476b5ffa1b1d7b5cc
|
4
|
+
data.tar.gz: d079cfde83d0747bedd31ae0ad602a5bc765c840
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 009f2455d59a1de25ba37f2ee19e092145c2446a511380baadbfb394e8bcd87864d29be93a9c254e8a762d00fa60b6d86e56d4089e20f7572f7eed0608600a33
|
7
|
+
data.tar.gz: 32b5486a3ab5abd9542a4d8637f3deaa0b1730d1bb4d3a69f88daecf48db690d51d10b6649a3882674e1c19035932ff1074704c00c15714f19ce33b5c95bef47
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Encx
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/encx`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'encx'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install encx
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec encx` to use the code located in this directory, ignoring other installed copies of this gem.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it ( https://github.com/[my-github-username]/encx/fork )
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "encx"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/encx.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'encx/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "encx"
|
8
|
+
spec.version = Encx::VERSION
|
9
|
+
spec.licenses = ['MIT']
|
10
|
+
spec.authors = ["yasuo kominami"]
|
11
|
+
spec.email = ["ykominami@gmail.com"]
|
12
|
+
|
13
|
+
spec.summary = %q{Encoding utility.}
|
14
|
+
spec.description = %q{Encoding utility.}
|
15
|
+
spec.homepage = ""
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
spec.required_ruby_version = '>= 1.9'
|
22
|
+
|
23
|
+
if spec.respond_to?(:metadata)
|
24
|
+
# spec.metadata['allowed_push_host'] = "http://mygemserver.com"
|
25
|
+
end
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "rspec"
|
30
|
+
end
|
data/exe/encx
ADDED
data/lib/encx.rb
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
require "encx/version"
|
2
|
+
|
3
|
+
module Encx
|
4
|
+
class Encx
|
5
|
+
def Encx.init(enc)
|
6
|
+
@@encx = Encx.new(enc)
|
7
|
+
end
|
8
|
+
|
9
|
+
def Encx.encx
|
10
|
+
@@encx
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(enc)
|
14
|
+
@encoding = enc
|
15
|
+
@encodings = [Encoding::Shift_JIS , Encoding::UTF_8 , Encoding::EUC_JP]
|
16
|
+
@ext_encodings = @encodings.select{ |x| x != @encoding }
|
17
|
+
@encoding_ary = [@encoding] + @ext_encodings
|
18
|
+
|
19
|
+
@re = nil
|
20
|
+
@last_match = nil
|
21
|
+
@last_match0 = nil
|
22
|
+
|
23
|
+
@cur_target = nil
|
24
|
+
@targets = []
|
25
|
+
@target_for_display = []
|
26
|
+
|
27
|
+
@error_target_item_hs = {}
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
def make_regexp( data , option = nil )
|
32
|
+
hs = {}
|
33
|
+
@encoding_ary.each do |enc|
|
34
|
+
if data.class == Array
|
35
|
+
hs[enc] = []
|
36
|
+
data.each do |d|
|
37
|
+
# d_puts "make_regexp d=#{d}"
|
38
|
+
hs[enc] << Regexp.new( convert(d , enc) , option )
|
39
|
+
end
|
40
|
+
else
|
41
|
+
# d_puts "make_regexp data=#{data}"
|
42
|
+
hs[enc] = Regexp.new( convert(data , enc) , option )
|
43
|
+
end
|
44
|
+
end
|
45
|
+
hs
|
46
|
+
end
|
47
|
+
|
48
|
+
def compare(l , hs)
|
49
|
+
ret2 = @encoding_ary.find{ |x|
|
50
|
+
begin
|
51
|
+
ret = hs[x].match(l)
|
52
|
+
if ret
|
53
|
+
ret = true
|
54
|
+
@re = hs[x]
|
55
|
+
@last_match = Regexp.last_match[1]
|
56
|
+
@last_match0 = Regexp.last_match[0]
|
57
|
+
else
|
58
|
+
ret = false
|
59
|
+
@last_match = nil
|
60
|
+
@last_match0 = nil
|
61
|
+
end
|
62
|
+
rescue => ex
|
63
|
+
exp = true
|
64
|
+
end
|
65
|
+
|
66
|
+
ret
|
67
|
+
}
|
68
|
+
|
69
|
+
ret2 != nil
|
70
|
+
end
|
71
|
+
|
72
|
+
def convert( d , enc = nil )
|
73
|
+
if enc
|
74
|
+
d.encode( enc , {:undef=>:replace, :invalid=>:replace, :replace => ""})
|
75
|
+
else
|
76
|
+
d.encode( @encoding , {:undef=>:replace, :invalid=>:replace, :replace => ""})
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def conv_env_sub( d , enc = nil )
|
81
|
+
val = nil
|
82
|
+
if enc != @encoding
|
83
|
+
begin
|
84
|
+
val = d.encode( enc )
|
85
|
+
# val = d.encode( enc , {:undef=>:replace, :invalid=>:replace, :replace => ""})
|
86
|
+
rescue => exp
|
87
|
+
ret = false
|
88
|
+
end
|
89
|
+
else
|
90
|
+
val=d
|
91
|
+
end
|
92
|
+
[ret , val]
|
93
|
+
end
|
94
|
+
|
95
|
+
def conv_env( d , enc = nil )
|
96
|
+
val = nil
|
97
|
+
if enc
|
98
|
+
ret , val = conv_env_sub( d , enc )
|
99
|
+
else
|
100
|
+
ret2 = @encoding_ary.find{ |enc|
|
101
|
+
ret , val = conv_env_sub( d , enc )
|
102
|
+
|
103
|
+
ret
|
104
|
+
}
|
105
|
+
end
|
106
|
+
val
|
107
|
+
end
|
108
|
+
|
109
|
+
def register_error( target , item )
|
110
|
+
@error_target_item_hs[target] ||= []
|
111
|
+
@error_target_item_hs[target] << item
|
112
|
+
end
|
113
|
+
|
114
|
+
def print_error_register_item
|
115
|
+
@error_target_item_hs.each do |k,v|
|
116
|
+
puts "##{k}"
|
117
|
+
v.each do |item|
|
118
|
+
puts "==#{item}"
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
data/lib/encx/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: encx
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- yasuo kominami
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-29 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.9'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
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
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Encoding utility.
|
56
|
+
email:
|
57
|
+
- ykominami@gmail.com
|
58
|
+
executables:
|
59
|
+
- encx
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- .rspec
|
65
|
+
- .travis.yml
|
66
|
+
- Gemfile
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/console
|
70
|
+
- bin/setup
|
71
|
+
- encx.gemspec
|
72
|
+
- exe/encx
|
73
|
+
- lib/encx.rb
|
74
|
+
- lib/encx/version.rb
|
75
|
+
homepage: ''
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '1.9'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.4.1
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: Encoding utility.
|
99
|
+
test_files: []
|