renc 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +4 -1
- data/CAHNGELOG.md +5 -0
- data/README.md +38 -8
- data/Rakefile +3 -3
- data/bin/console +3 -3
- data/lib/renc.rb +23 -2
- data/lib/renc/version.rb +1 -1
- data/renc.gemspec +9 -9
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36fc265a71968fed982b140c1925848904ce5a26
|
4
|
+
data.tar.gz: 062f3218d2e3c643d57255f03ef5a5bfe5862bb8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4cfd70b202d6244d7e0657fbc4bb04b4733dd9252e6ddc8bd218acece2d1dd119fd5e0c49f52a2925c04342e1086c03df56b9c0aa9c1c1b8d9f9d92134a5536
|
7
|
+
data.tar.gz: 9164395218da7e9d5dc74402b13f278e3410ded27182b650cb5e7b9ddff9a436d20ad94118915356e1d008b7fedeb79b81f9dab58c3a3f34b2159302e0f85548
|
data/.travis.yml
CHANGED
data/CAHNGELOG.md
ADDED
data/README.md
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
# Renc
|
2
2
|
|
3
|
-
Welcome to your new gem!
|
3
|
+
Welcome to your new gem!
|
4
|
+
In this directory, you'll find the files you need to be able to package up your Ruby library into a gem.
|
5
|
+
Put your Ruby code in the file `lib/renc`.
|
6
|
+
To experiment with that code, run `bin/console` for an interactive prompt.
|
4
7
|
|
5
|
-
|
8
|
+
recurse encoding for Hash and Array.
|
6
9
|
|
7
10
|
## Installation
|
8
11
|
|
@@ -22,20 +25,47 @@ Or install it yourself as:
|
|
22
25
|
|
23
26
|
## Usage
|
24
27
|
|
25
|
-
|
28
|
+
```ruby
|
29
|
+
require 'renc'
|
30
|
+
|
31
|
+
str_ascii = 'hello renc!'.encode(Encoding::ASCII)
|
32
|
+
str_ascii.encoding # => #<Encoding::US-ASCII>
|
33
|
+
Renc.enc(str_ascii, Encoding::UTF_8).encoding # => #<Encoding::UTF-8>
|
34
|
+
|
35
|
+
hash_val = { a: str_ascii }
|
36
|
+
hash_val[:a].encoding # => Encoding::ASCII
|
37
|
+
Renc.enc(hash_val, Encoding::UTF_8)[:a].encoding # => #<Encoding::UTF-8>
|
38
|
+
|
39
|
+
array_val = [str_ascii]
|
40
|
+
array_val.first.encoding # => Encoding::ASCII
|
41
|
+
Renc.enc(array_val, Encoding::UTF_8).first.encoding # => #<Encoding::UTF-8>
|
42
|
+
```
|
26
43
|
|
27
44
|
## Development
|
28
45
|
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies.
|
46
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
47
|
+
Then, run `rake spec` to run the tests.
|
48
|
+
You can also run `bin/console` for an interactive prompt
|
49
|
+
that will allow you to experiment.
|
30
50
|
|
31
|
-
To install this gem onto your local machine, run `bundle exec rake install`.
|
51
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
52
|
+
To release a new version, update the version number in `version.rb`,
|
53
|
+
and then run `bundle exec rake release`,
|
54
|
+
which will create a git tag for the version,
|
55
|
+
push git commits and tags,
|
56
|
+
and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
57
|
|
33
58
|
## Contributing
|
34
59
|
|
35
|
-
Bug reports and pull requests are welcome on
|
60
|
+
Bug reports and pull requests are welcome on
|
61
|
+
GitHub at https://github.com/[USERNAME]/renc.
|
62
|
+
This project is intended to be a safe,
|
63
|
+
welcoming space for collaboration,
|
64
|
+
and contributors are expected to adhere to the
|
65
|
+
[Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
66
|
|
37
67
|
|
38
68
|
## License
|
39
69
|
|
40
|
-
The gem is available as open source
|
41
|
-
|
70
|
+
The gem is available as open source
|
71
|
+
under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'renc'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +10,5 @@ require "renc"
|
|
10
10
|
# require "pry"
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
13
|
+
require 'irb'
|
14
14
|
IRB.start
|
data/lib/renc.rb
CHANGED
@@ -1,5 +1,26 @@
|
|
1
|
-
require
|
1
|
+
require 'renc/version'
|
2
2
|
|
3
|
+
# namespace
|
3
4
|
module Renc
|
4
|
-
|
5
|
+
def self.enc(obj, encoding = Encoding::UTF_8)
|
6
|
+
case obj
|
7
|
+
when String then obj.encode(encoding)
|
8
|
+
when Hash then enc_hash(obj, encoding)
|
9
|
+
when Array then enc_array(obj, encoding)
|
10
|
+
else obj
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# private
|
15
|
+
|
16
|
+
def self.enc_hash(obj, encoding)
|
17
|
+
obj.each_with_object({}) do |args, h|
|
18
|
+
key, val = args
|
19
|
+
h[key] = enc(val, encoding)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.enc_array(obj, encoding)
|
24
|
+
obj.map { |val| enc(val, encoding) }
|
25
|
+
end
|
5
26
|
end
|
data/lib/renc/version.rb
CHANGED
data/renc.gemspec
CHANGED
@@ -4,24 +4,24 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'renc/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'renc'
|
8
8
|
spec.version = Renc::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['k-ta-yamada']
|
10
|
+
spec.email = ['key.luvless@gmail.com']
|
11
11
|
|
12
12
|
spec.summary = 'recurse encoding for Hash and Array.'
|
13
13
|
spec.description = 'recurse encoding for Hash and Array.'
|
14
14
|
spec.homepage = 'https://github.com/k-ta-yamada/renc'
|
15
|
-
spec.license =
|
15
|
+
spec.license = 'MIT'
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
-
spec.bindir =
|
18
|
+
spec.bindir = 'exe'
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
-
spec.require_paths = [
|
20
|
+
spec.require_paths = ['lib']
|
21
21
|
|
22
|
-
spec.add_development_dependency
|
23
|
-
spec.add_development_dependency
|
24
|
-
spec.add_development_dependency
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
25
25
|
|
26
26
|
spec.add_development_dependency 'pry'
|
27
27
|
spec.add_development_dependency 'pry-doc'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: renc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- k-ta-yamada
|
@@ -132,6 +132,7 @@ files:
|
|
132
132
|
- ".gitignore"
|
133
133
|
- ".rspec"
|
134
134
|
- ".travis.yml"
|
135
|
+
- CAHNGELOG.md
|
135
136
|
- CODE_OF_CONDUCT.md
|
136
137
|
- Gemfile
|
137
138
|
- LICENSE.txt
|
@@ -162,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
162
163
|
version: '0'
|
163
164
|
requirements: []
|
164
165
|
rubyforge_project:
|
165
|
-
rubygems_version: 2.
|
166
|
+
rubygems_version: 2.5.1
|
166
167
|
signing_key:
|
167
168
|
specification_version: 4
|
168
169
|
summary: recurse encoding for Hash and Array.
|