dothash 2.0.2 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +6 -1
- data/README.md +8 -1
- data/lib/dothash/hash.rb +12 -7
- data/lib/dothash/version.rb +2 -2
- data/lib/dothash.rb +1 -1
- metadata +3 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 184c3bbaf467d46a428209cec433468d91cc121488e91265f8218bf03074a5de
|
4
|
+
data.tar.gz: 3203a7d7d8448588c3e959b9efb82311d8428643f507f12bfaaca0f02569c298
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f38f477936190b526b46aa86d9d5e28609d38a54059b6dfa46995f4dd59cc57ae491b2e279f0bdf156af22b4d23d3f718d7571d9bfd418fdf535937c84915f9
|
7
|
+
data.tar.gz: 483b067bc5ab71464cc9e03a3dc06d09a1c40f751fb2d49b1ad341f391bac39582065f24290a619d754bf76ff07c5e5707c4938e282b9e38d4e998230667bc94
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
### 2.1.0 (2024.01.10)
|
2
|
+
|
3
|
+
* add one_based notation
|
4
|
+
* gh actions
|
5
|
+
|
1
6
|
### 2.0.2 (2017.04.07)
|
2
7
|
|
3
8
|
* fix travis integration
|
@@ -5,7 +10,7 @@
|
|
5
10
|
|
6
11
|
### 2.0.1 (2016.10.05)
|
7
12
|
|
8
|
-
* remove unused code
|
13
|
+
* remove unused code
|
9
14
|
|
10
15
|
### 2.0.0 (2016.10.05)
|
11
16
|
|
data/README.md
CHANGED
@@ -30,9 +30,15 @@ dhash = Dothash::Hash.with_dots hash
|
|
30
30
|
puts dhash
|
31
31
|
# {"x.y"=>1, "x.z.a1"=>8, "x.z.a2"=>10, "v.0"=>1, "v.1.y"=>2, "v.1.z"=>3}
|
32
32
|
|
33
|
-
puts
|
33
|
+
puts dhash.class
|
34
34
|
# Hash
|
35
35
|
|
36
|
+
dhash_1 = Dothash::Hash.with_dots_one_based hash
|
37
|
+
|
38
|
+
puts dhash
|
39
|
+
# {"x.y"=>1, "x.z.a1"=>8, "x.z.a2"=>10, "v.1"=>1, "v.2.y"=>2, "v.2.z"=>3}
|
40
|
+
|
41
|
+
|
36
42
|
hash2 = Dothash::Hash.without_dots(dhash)
|
37
43
|
|
38
44
|
puts hash2
|
@@ -52,3 +58,4 @@ See [semver.org][semver]
|
|
52
58
|
5. Create new Pull Request
|
53
59
|
|
54
60
|
[semver]: http://semver.org/
|
61
|
+
|
data/lib/dothash/hash.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (C) 2016
|
3
|
+
# Copyright (C) 2016 - 2024 Szymon Kopciewski
|
4
4
|
#
|
5
5
|
# This file is part of Dothash.
|
6
6
|
#
|
@@ -19,23 +19,28 @@
|
|
19
19
|
|
20
20
|
module Dothash
|
21
21
|
class Hash
|
22
|
-
def self.with_dots(hash, prefix = nil)
|
22
|
+
def self.with_dots(hash, prefix = nil, one_based = false)
|
23
23
|
raise ArgumentError, "You should pass only Hash here" unless hash.is_a? ::Hash
|
24
24
|
hash.each_with_object({}) do |(key, value), memo|
|
25
25
|
new_key = [prefix, key].compact.join(".")
|
26
|
-
memo.merge! with_dots_deeper(value, new_key)
|
26
|
+
memo.merge! with_dots_deeper(value, new_key, one_based)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
|
30
|
+
def self.with_dots_one_based(hash, prefix = nil)
|
31
|
+
with_dots hash, prefix, true
|
32
|
+
end
|
33
|
+
|
34
|
+
private_class_method def self.with_dots_deeper(value, new_key, one_based)
|
31
35
|
if value.is_a?(::Hash)
|
32
|
-
with_dots(value, new_key)
|
36
|
+
with_dots(value, new_key, one_based)
|
33
37
|
elsif value.is_a? ::Array
|
34
38
|
value.each_with_object({}).with_index do |(avalue, memo), index|
|
35
|
-
|
39
|
+
new_index = one_based ? index + 1 : index
|
40
|
+
memo.merge! with_dots({new_index => avalue}, new_key, one_based)
|
36
41
|
end
|
37
42
|
else
|
38
|
-
{
|
43
|
+
{new_key => value}
|
39
44
|
end
|
40
45
|
end
|
41
46
|
|
data/lib/dothash/version.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (C) 2016
|
3
|
+
# Copyright (C) 2016 - 2024 Szymon Kopciewski
|
4
4
|
#
|
5
5
|
# This file is part of Dothash.
|
6
6
|
#
|
@@ -18,5 +18,5 @@
|
|
18
18
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
19
|
|
20
20
|
module Dothash
|
21
|
-
VERSION = "2.0
|
21
|
+
VERSION = "2.1.0"
|
22
22
|
end
|
data/lib/dothash.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dothash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Szymon Kopciewski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: pry
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: minitest
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,20 +66,6 @@ dependencies:
|
|
80
66
|
- - ">="
|
81
67
|
- !ruby/object:Gem::Version
|
82
68
|
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: codeclimate-test-reporter
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
69
|
description: Dot notation for Hash
|
98
70
|
email:
|
99
71
|
- s.kopciewski@gmail.com
|
@@ -127,8 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
99
|
- !ruby/object:Gem::Version
|
128
100
|
version: '0'
|
129
101
|
requirements: []
|
130
|
-
|
131
|
-
rubygems_version: 2.4.8
|
102
|
+
rubygems_version: 3.4.10
|
132
103
|
signing_key:
|
133
104
|
specification_version: 4
|
134
105
|
summary: Dot notation for Hash
|