nested_hash_helper 1.0.0 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e7f67ec121f9910b50c6a7f7b61941bcd6e1784e
4
- data.tar.gz: a0b23de228d5f145b977552ffdcc2286e93abca8
3
+ metadata.gz: 76ebe04ac7eac3f35fe61a2d1786a19119a1d43c
4
+ data.tar.gz: 24eda8a1904f0bb5cda4d50b0f5a2cc3973d4099
5
5
  SHA512:
6
- metadata.gz: 83c7ec8e9a4f938ac89a6777d1d819e5eeffaa15b0968a4b2a8226fe2d974662b1d4cc59992e51092df31bd3d968e142eb0a720781454c45de344c639eaae167
7
- data.tar.gz: 96ad4403b6123c37880e68f61db2d480792e33e77674ba73e245aa43afcf38115dfa3c8a3e20d2d9815da52229d8360375928e20b420db80abc331ac313babb4
6
+ metadata.gz: 27988c8e92a6cafc526a884e63f5643d29faed7947f55f529de252879b58d335285fcfb848233cf99580834cf535d57b6836d2c25d2eb4ab8dd89290c21ee449
7
+ data.tar.gz: bb9abbae013077a9e79fa3d19c37e6f099186543e8536ce638f3d2e760d5bd098876f9774570f4ad70979c3d346d728012a97e32abbd6afc38319d1ea29509aa
data/README.md CHANGED
@@ -8,75 +8,72 @@ Development has just begun and is active and we will fix bugs , enhance function
8
8
 
9
9
  ## Usage
10
10
 
11
- 1) deep_except(*excluded_keys)
11
+ ###1) deep_except(*excluded_keys)
12
12
 
13
13
  This method extends the functionality of except method of ruby hash to nested hash. pass any number of keys to delete them from the hash . Just pass the immediate key and not the entire key path in the hash .
14
14
 
15
15
  Syntax
16
+ ```ruby
17
+ a = {:name => "vivek" , :age => 22}
18
+ a.deep_except(:name)
19
+ output ==> {:age => 22}
20
+ ```
16
21
 
17
- a = {:name => "vivek" , :age => 22}
22
+ ```ruby
23
+ a = {:user => {:name => "vivek" , :age => 22 , :phone => 3333}}
24
+ a.deep_except(:phone , :age)
25
+ output ==> {:user => {:name => "vivek"}}
26
+ ```
18
27
 
19
- a.deep_except(:name)
20
28
 
21
- output ==> {:age => 22}
22
29
 
23
- a = {:user => {:name => "vivek" , :age => 22 , :phone => 3333}}
24
-
25
- a.deep_except(:phone , :age)
26
-
27
- output ==> {:user => {:name => "vivek"}}
28
-
29
- 2) deep_delete_empty
30
+ ### 2) deep_delete_empty
30
31
 
31
32
  This method deletes all the keys whose value is either empty or nil .
32
33
 
33
- Syntax
34
-
34
+ Syntax
35
+ ```ruby
35
36
  a = {:user => {:name => "" , :age => 22 , :phone => 3333}}
36
-
37
- a.deep_delete_empty
38
-
37
+ a.deep_delete_empty
39
38
  output ==> {:user => {:age => 22 , :phone => 3333}}
39
+ ```
40
40
 
41
- 3) find_depth
42
41
 
43
- This method finds the depth of your nested hash.
44
-
45
- Syntax
42
+ ### 3) find_depth
46
43
 
47
- a = {:user => {:name => {:last_name => "Vivek"}}}
44
+ This method finds the depth of your nested hash.
48
45
 
49
- a.find_depth
46
+ Syntax
47
+ ```ruby
48
+ a = {:user => {:name => {:last_name => "Vivek"}}}
49
+ a.find_depth
50
+ output ==> 3
51
+ ```
50
52
 
51
- output ==> 3
52
53
 
53
- 4) find_deep_intersection
54
+ ### 4) find_deep_intersection
54
55
 
55
56
  This method returns intersection of two nested Hashes.
56
57
 
57
- Syntax
58
-
59
- a = {:user => {:name => "vivek" , :age => 22 , :phone => 3333}}
60
-
61
- b = {:user => {:name => "rakesh" , :age => 22 , :phone => 3333}}
62
-
63
- a.find_deep_intersection(b)
64
-
65
- output ==> {:user => {:age => 22 , :phone => 3333}}
58
+ Syntax
59
+ ```ruby
60
+ a = {:user => {:name => "vivek" , :age => 22 , :phone => 3333}}
61
+ b = {:user => {:name => "rakesh" , :age => 22 , :phone => 3333}}
62
+ a.find_deep_intersection(b)
63
+ output ==> {:user => {:age => 22 , :phone => 3333}}
64
+ ```
66
65
 
67
- 5) find_deep_keys
66
+ ### 5) find_deep_keys
68
67
 
69
68
  This method return all the parent keys of the corresponding value.
70
69
 
71
- Syntax
72
-
73
- a = {:gh => {:jj => {:pop => "bbb" , :olo => "ooooo"}} , :pp => "ooooo"}
74
70
 
75
- a.find_deep_keys("ooooo")
76
-
77
- output ==> [:gh , :jj , :olo]
78
-
79
-
71
+ Syntax
72
+ ```ruby
73
+ a = {:gh => {:jj => {:pop => "bbb" , :olo => "ooooo"}} , :pp => "ooooo"}
74
+ a.find_deep_keys("ooooo")
75
+ output ==> [:gh , :jj , :olo]
76
+ ```
80
77
 
81
78
 
82
79
  ## Installation
@@ -89,15 +86,12 @@ gem 'nested_hash_helper'
89
86
 
90
87
  And then execute:
91
88
 
92
- $ bundle
89
+ $ bundle install
93
90
 
94
91
  Or install it yourself as:
95
92
 
96
93
  $ gem install nested_hash_helper
97
94
 
98
- ## Usage
99
-
100
- TODO: Write usage instructions here
101
95
 
102
96
  ## Development
103
97
 
@@ -109,7 +103,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
109
103
 
110
104
  Do Contribute if you come across any bugs / any important feature you feel is essential.
111
105
 
112
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/nested_hash_helper.
106
+ Bug reports and pull requests are welcome on GitHub at https://github.com/vivek3894/nested_hash_helper.
113
107
 
114
108
 
115
109
  ## License
@@ -1,3 +1,3 @@
1
1
  module NestedHashHelper
2
- VERSION = "1.0.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -77,6 +77,48 @@ def find_deep_keys(value)
77
77
  deep_keys
78
78
  end
79
79
 
80
+ def hash_to_array
81
+ current_class = self.class
82
+ final_array = []
83
+ self.each do | current_keys , current_value |
84
+ temp_array = []
85
+ if current_value.is_a?(current_class)
86
+ temp_array.push(current_keys)
87
+ temp_array += current_value.hash_to_array
88
+ final_array.push(temp_array)
89
+ else
90
+ temp_array.push(current_keys)
91
+ temp_array.push(current_value)
92
+ final_array.push(temp_array)
93
+ end
94
+ end
95
+ final_array
96
+ end
97
+
98
+ def find_all_values(key)
99
+ current_class = self.class
100
+ values = []
101
+ self.each do |current_keys , current_value|
102
+ if current_value.is_a?(current_class)
103
+ values += current_value.find_all_values(key)
104
+ elsif current_keys == key
105
+ values.push(current_value)
106
+ end
107
+ end
108
+ values
109
+ end
110
+
111
+ def deep_delete(key)
112
+ current_class = self.class
113
+ self.each do |current_keys , current_value|
114
+ if current_keys == key
115
+ self.delete(current_keys)
116
+ elsif current_value.is_a?(current_class)
117
+ current_value.deep_delete(key)
118
+ end
119
+ end
120
+ end
121
+
80
122
  end
81
123
 
82
124
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nested_hash_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - vivek n
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-06 00:00:00.000000000 Z
11
+ date: 2017-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler