renc 2.0.0 → 2.1.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: 6d9665ebabc71fd95740388777621dce95bb7b7c
4
- data.tar.gz: ca951228ca44d73c03df61a4054cc90a3147e55f
3
+ metadata.gz: b87be5d18214f6f0241ba83689760173435cd375
4
+ data.tar.gz: 7473827a7e4e0d4a383ed28fa148b820978dc96f
5
5
  SHA512:
6
- metadata.gz: 95ec060b743f14a0585dacc96222fe8a77a68bce26d7931868ece0c8140192972f820ad3ff326d87a41136d4949eb093ffaa126c9a021dad2d995b6f2b042eaa
7
- data.tar.gz: 58cfba8cbf227d6230bc32e0dd5b62a65103ea2ce97a9ef377a3782006ad7256affe5733bc13ed2f32c86e6e232e5e3b23ac0449f7c72f5596e6a2e7c2c6a427
6
+ metadata.gz: ca57295a0c03eb1e6cc5b08cb96908c9d3a5e73654c38ee90ff2315aa958f497d86ff8c56519abd1690b12c809248648f35d227a6dce009d5661f19df69e6f83
7
+ data.tar.gz: 6c47aac8531825d80c21c4c64ec2798a57b44ccb85b7e1093bfc20155bd09a8209d7fff2787cc384c2838c8de8528e7abf27f07ca54dd89b348f74976df08538
@@ -1,3 +1,7 @@
1
+ # v2.1.0
2
+ - [issue #21](https://github.com/k-ta-yamada/renc/issues/21)
3
+ change class structure; Separate Configuration #21
4
+
1
5
  # v2.0.0
2
6
  - [issue #10](https://github.com/k-ta-yamada/renc/issues/10)
3
7
  Changing default_encoding by os #10
data/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  # Renc
8
8
 
9
- recurse encoding for Hash and Array.
9
+ recursive encode for Hash and Array.
10
10
 
11
11
 
12
12
  ## Installation
@@ -1,6 +1,7 @@
1
1
  require 'renc/version'
2
+ require 'renc/configuration'
2
3
 
3
- # recurse encoding for Hash and Array.
4
+ # recursive encode for Hash and Array.
4
5
  # @example
5
6
  # require 'renc'
6
7
  #
@@ -8,55 +9,13 @@ require 'renc/version'
8
9
  # extend Renc
9
10
  # @see #renc
10
11
  module Renc
12
+ extend Configuration
13
+
11
14
  # for include #renc method
12
15
  TARGET_CLASS = [String, Array, Hash].freeze
13
16
  TARGET_CLASS.each { |klass| klass.send(:include, self) }
14
17
 
15
- # this gem's default configured encoding
16
- # @see Encoding.default_external
17
- DEFAULT_ENCODING = Encoding.default_external
18
-
19
- # this gem's default options for String#encode
20
- # @see String#encode
21
- DEFAULT_OPTIONS = { undef: :replace }.freeze
22
-
23
- class << self
24
- # return @default_encoding
25
- # @return [Encoding] @default_encoding
26
- # @see DEFAULT_ENCODING
27
- def default_encoding
28
- @default_encoding ||= DEFAULT_ENCODING
29
- end
30
-
31
- # configure default encoding
32
- # @example
33
- # Renc.default_encoding = 1 # => Renc::ConfigureError
34
- # Renc.default_encoding = Encoding::ASCII
35
- # @param encoding [Encoding]
36
- def default_encoding=(encoding)
37
- raise TypeError unless encoding.is_a?(Encoding)
38
- @default_encoding = encoding
39
- end
40
-
41
- # return @default_options
42
- # @return [Encoding] @default_options
43
- # @see DEFAULT_OPTIONS
44
- def default_options
45
- @default_options ||= DEFAULT_OPTIONS
46
- end
47
-
48
- # configure default options
49
- # @example
50
- # Renc.default_options = 1 # => Renc::ConfigureError
51
- # Renc.default_options = { undef: nil }
52
- # @param options [Hash]
53
- def default_options=(options)
54
- raise TypeError unless options.is_a?(Hash)
55
- @default_options = options
56
- end
57
- end
58
-
59
- # recurse encoding for Hash and Array.
18
+ # recursive encode for Hash and Array.
60
19
  # @example
61
20
  # # for example
62
21
  # default_src_encoding # => #<Encoding:UTF-8>
@@ -99,14 +58,14 @@ module Renc
99
58
  end
100
59
  end
101
60
 
102
- # recurse encoding for Hash values of String.
61
+ # recursive encode for Hash values of String.
103
62
  def renc_hash(obj, encoding, options)
104
63
  obj.each_with_object({}) do |(key, val), h|
105
64
  h[key] = renc_internal(val, encoding, options)
106
65
  end
107
66
  end
108
67
 
109
- # recurse encoding for Array values of String.
68
+ # recursive encode for Array values of String.
110
69
  def renc_array(obj, encoding, options)
111
70
  obj.map { |val| renc_internal(val, encoding, options) }
112
71
  end
@@ -0,0 +1,46 @@
1
+ module Renc
2
+ # namespace
3
+ module Configuration
4
+ # this gem's default configured encoding
5
+ # @see Encoding.default_external
6
+ DEFAULT_ENCODING = Encoding.default_external
7
+
8
+ # this gem's default options for String#encode
9
+ # @see String#encode
10
+ DEFAULT_OPTIONS = { undef: :replace }.freeze
11
+
12
+ # return @default_encoding
13
+ # @return [Encoding] @default_encoding
14
+ # @see DEFAULT_ENCODING
15
+ def default_encoding
16
+ @default_encoding ||= DEFAULT_ENCODING
17
+ end
18
+
19
+ # configure default encoding
20
+ # @example
21
+ # Renc.default_encoding = 1 # => Renc::ConfigureError
22
+ # Renc.default_encoding = Encoding::ASCII
23
+ # @param encoding [Encoding]
24
+ def default_encoding=(encoding)
25
+ raise TypeError unless encoding.is_a?(Encoding)
26
+ @default_encoding = encoding
27
+ end
28
+
29
+ # return @default_options
30
+ # @return [Encoding] @default_options
31
+ # @see DEFAULT_OPTIONS
32
+ def default_options
33
+ @default_options ||= DEFAULT_OPTIONS
34
+ end
35
+
36
+ # configure default options
37
+ # @example
38
+ # Renc.default_options = 1 # => Renc::ConfigureError
39
+ # Renc.default_options = { undef: nil }
40
+ # @param options [Hash]
41
+ def default_options=(options)
42
+ raise TypeError unless options.is_a?(Hash)
43
+ @default_options = options
44
+ end
45
+ end
46
+ end
@@ -1,3 +1,3 @@
1
1
  module Renc
2
- VERSION = '2.0.0'.freeze
2
+ VERSION = '2.1.0'.freeze
3
3
  end
@@ -11,8 +11,8 @@ Gem::Specification.new do |spec|
11
11
 
12
12
  spec.required_ruby_version = '>= 2.0.0'
13
13
 
14
- spec.summary = 'recurse encoding for Hash and Array.'
15
- spec.description = 'recurse encoding for Hash and Array.'
14
+ spec.summary = 'recursive encode for Hash and Array.'
15
+ spec.description = 'recursive encode for Hash and Array.'
16
16
  spec.homepage = 'https://github.com/k-ta-yamada/renc'
17
17
  spec.license = 'MIT'
18
18
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: renc
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - k-ta-yamada
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-15 00:00:00.000000000 Z
11
+ date: 2017-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -136,7 +136,7 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
- description: recurse encoding for Hash and Array.
139
+ description: recursive encode for Hash and Array.
140
140
  email:
141
141
  - key.luvless@gmail.com
142
142
  executables: []
@@ -157,6 +157,7 @@ files:
157
157
  - bin/console
158
158
  - bin/setup
159
159
  - lib/renc.rb
160
+ - lib/renc/configuration.rb
160
161
  - lib/renc/version.rb
161
162
  - renc.gemspec
162
163
  homepage: https://github.com/k-ta-yamada/renc
@@ -182,5 +183,5 @@ rubyforge_project:
182
183
  rubygems_version: 2.6.8
183
184
  signing_key:
184
185
  specification_version: 4
185
- summary: recurse encoding for Hash and Array.
186
+ summary: recursive encode for Hash and Array.
186
187
  test_files: []