renc 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 67a0227a33b1e168d90bbd365fec82f64a6ff630
4
- data.tar.gz: b2dd3694650095a8e6238973b2243cc642169d56
3
+ metadata.gz: 36fc265a71968fed982b140c1925848904ce5a26
4
+ data.tar.gz: 062f3218d2e3c643d57255f03ef5a5bfe5862bb8
5
5
  SHA512:
6
- metadata.gz: 2b83969f8487705da91a5e6dcd821e8862ac889e2696c754c22229889541e66273bcc2fe1ad4408dbf9c4dc2d35c1e8dba7554c11b5bd0dc774c24797a39a85b
7
- data.tar.gz: 0106e1ff5cda220d28914d9448360b04541299175926db27b698d5a34aa8477b5ca5c5b6079563d5798edbd2b719bb68d17c55051ddedf6aeccadaa697ac6108
6
+ metadata.gz: b4cfd70b202d6244d7e0657fbc4bb04b4733dd9252e6ddc8bd218acece2d1dd119fd5e0c49f52a2925c04342e1086c03df56b9c0aa9c1c1b8d9f9d92134a5536
7
+ data.tar.gz: 9164395218da7e9d5dc74402b13f278e3410ded27182b650cb5e7b9ddff9a436d20ad94118915356e1d008b7fedeb79b81f9dab58c3a3f34b2159302e0f85548
@@ -1,4 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.5
3
+ - 2.3.0
4
+ - 2.2.3
5
+ - 2.1.7
6
+ - 2.0.0
4
7
  before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,5 @@
1
+ # v0.2.0
2
+ - implement base features.
3
+
4
+ # v0.1.0
5
+ - sorry, this version is dummy.
data/README.md CHANGED
@@ -1,8 +1,11 @@
1
1
  # Renc
2
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/renc`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Delete this and the text above, and describe your gem
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
- TODO: Write usage instructions here
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. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
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`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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 GitHub at https://github.com/[USERNAME]/renc. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
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 under the terms of the [MIT License](http://opensource.org/licenses/MIT).
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
@@ -1,6 +1,6 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "renc"
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 "irb"
13
+ require 'irb'
14
14
  IRB.start
@@ -1,5 +1,26 @@
1
- require "renc/version"
1
+ require 'renc/version'
2
2
 
3
+ # namespace
3
4
  module Renc
4
- # Your code goes here...
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
@@ -1,3 +1,3 @@
1
1
  module Renc
2
- VERSION = "0.1.0"
2
+ VERSION = '0.2.0'.freeze
3
3
  end
@@ -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 = "renc"
7
+ spec.name = 'renc'
8
8
  spec.version = Renc::VERSION
9
- spec.authors = ["k-ta-yamada"]
10
- spec.email = ["key.luvless@gmail.com"]
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 = "MIT"
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 = "exe"
18
+ spec.bindir = 'exe'
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
- spec.require_paths = ["lib"]
20
+ spec.require_paths = ['lib']
21
21
 
22
- spec.add_development_dependency "bundler", "~> 1.11"
23
- spec.add_development_dependency "rake", "~> 10.0"
24
- spec.add_development_dependency "rspec", "~> 3.0"
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.1.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.2.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.