dothash 2.0.1 → 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
- SHA1:
3
- metadata.gz: a4407f726c2e756b296a9b8dc864ea6053a59c11
4
- data.tar.gz: 094191c6ac7554a71ed122a8f8809d2e674cd2c8
2
+ SHA256:
3
+ metadata.gz: 184c3bbaf467d46a428209cec433468d91cc121488e91265f8218bf03074a5de
4
+ data.tar.gz: 3203a7d7d8448588c3e959b9efb82311d8428643f507f12bfaaca0f02569c298
5
5
  SHA512:
6
- metadata.gz: cf1d2d027be1bd3cfb567a13d49aedf138312f30682f19effd95358291028a79f403742f8e7fe149b8de8910a9e0db71d2a7bba26825acd58f55a534ced6bebe
7
- data.tar.gz: 83a44a64c20ab7dce984b7b6d073ee5963775bf9a23b85dfe3a09257309ab51eee0c3a295999e6e964c5cc17a34315d4332081468529fa942d750812eca76dcd
6
+ metadata.gz: 9f38f477936190b526b46aa86d9d5e28609d38a54059b6dfa46995f4dd59cc57ae491b2e279f0bdf156af22b4d23d3f718d7571d9bfd418fdf535937c84915f9
7
+ data.tar.gz: 483b067bc5ab71464cc9e03a3dc06d09a1c40f751fb2d49b1ad341f391bac39582065f24290a619d754bf76ff07c5e5707c4938e282b9e38d4e998230667bc94
data/CHANGELOG.md CHANGED
@@ -1,11 +1,21 @@
1
- === 2.0.1 (2016.10.05)
1
+ ### 2.1.0 (2024.01.10)
2
2
 
3
- * remove unused code
3
+ * add one_based notation
4
+ * gh actions
4
5
 
5
- === 2.0.0 (2016.10.05)
6
+ ### 2.0.2 (2017.04.07)
7
+
8
+ * fix travis integration
9
+ * update license
10
+
11
+ ### 2.0.1 (2016.10.05)
12
+
13
+ * remove unused code
14
+
15
+ ### 2.0.0 (2016.10.05)
6
16
 
7
17
  * add conversion from opposite direction
8
18
 
9
- === 1.0.0 (2016.10.04)
19
+ ### 1.0.0 (2016.10.04)
10
20
 
11
21
  * publication of the code
data/Gemfile CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  source "https://rubygems.org"
2
3
 
3
4
  # Specify your gem's dependencies in mayaml.gemspec
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/dothash.svg)](http://badge.fury.io/rb/dothash)
4
4
  [![Code Climate](https://codeclimate.com/github/skopciewski/dothash/badges/gpa.svg)](https://codeclimate.com/github/skopciewski/dothash)
5
+ [![Dependency Status](https://gemnasium.com/badges/github.com/skopciewski/dothash.svg)](https://gemnasium.com/github.com/skopciewski/dothash)
5
6
 
6
7
  Hash to dot notation.
7
8
 
@@ -29,9 +30,15 @@ dhash = Dothash::Hash.with_dots hash
29
30
  puts dhash
30
31
  # {"x.y"=>1, "x.z.a1"=>8, "x.z.a2"=>10, "v.0"=>1, "v.1.y"=>2, "v.1.z"=>3}
31
32
 
32
- puts dh.class
33
+ puts dhash.class
33
34
  # Hash
34
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
+
35
42
  hash2 = Dothash::Hash.without_dots(dhash)
36
43
 
37
44
  puts hash2
@@ -51,3 +58,4 @@ See [semver.org][semver]
51
58
  5. Create new Pull Request
52
59
 
53
60
  [semver]: http://semver.org/
61
+
data/lib/dothash/hash.rb CHANGED
@@ -1,6 +1,6 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
- # Copyright (C) 2016 Szymon Kopciewski
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
- private_class_method def self.with_dots_deeper(value, new_key)
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
- memo.merge! with_dots({ index => avalue }, new_key)
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
- { new_key => value }
43
+ {new_key => value}
39
44
  end
40
45
  end
41
46
 
@@ -1,6 +1,6 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
- # Copyright (C) 2016 Szymon Kopciewski
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.1".freeze
21
+ VERSION = "2.1.0"
22
22
  end
data/lib/dothash.rb CHANGED
@@ -1,6 +1,6 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
- # Copyright (C) 2016 Szymon Kopciewski
3
+ # Copyright (C) 2016-2024 Szymon Kopciewski
4
4
  #
5
5
  # This file is part of Dothash.
6
6
  #
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.1
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: 2016-10-05 00:00:00.000000000 Z
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
@@ -67,7 +53,7 @@ dependencies:
67
53
  - !ruby/object:Gem::Version
68
54
  version: '0'
69
55
  - !ruby/object:Gem::Dependency
70
- name: codeclimate-test-reporter
56
+ name: simplecov
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
59
  - - ">="
@@ -113,8 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
99
  - !ruby/object:Gem::Version
114
100
  version: '0'
115
101
  requirements: []
116
- rubyforge_project:
117
- rubygems_version: 2.4.8
102
+ rubygems_version: 3.4.10
118
103
  signing_key:
119
104
  specification_version: 4
120
105
  summary: Dot notation for Hash