hash_multi_tool 0.1.0 → 0.1.1

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.
data/Gemfile.lock ADDED
@@ -0,0 +1,27 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ hash_multi_tool (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.1.3)
10
+ rake (10.4.2)
11
+ rspec (2.11.0)
12
+ rspec-core (~> 2.11.0)
13
+ rspec-expectations (~> 2.11.0)
14
+ rspec-mocks (~> 2.11.0)
15
+ rspec-core (2.11.1)
16
+ rspec-expectations (2.11.2)
17
+ diff-lcs (~> 1.1.3)
18
+ rspec-mocks (2.11.2)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ bundler (~> 1.9)
25
+ hash_multi_tool!
26
+ rake (~> 10.0)
27
+ rspec
data/README.md CHANGED
@@ -22,7 +22,28 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+ ARR_HASH = [{ foo: 'a', bar: 4 },
26
+ { foo: 'b', bar: 3 },
27
+ { foo: 'c', bar: 1 },
28
+ { foo: 'b', bar: 4 }]
29
+
30
+ 1) HashMultiTool.sort_by_order ARR_HASH, [:bar, :foo]
31
+
32
+ Note: By default it will sort in ASC order
33
+
34
+ If you Want to sort in DESC order.
35
+
36
+ HashMultiTool.sort_by_order ARR_HASH, [:bar, :foo], "DESC"
37
+
38
+ 2) Find array of hashes of matched key values :-
39
+
40
+ HashMultiTool.select_by_key_value ARR_HASH_ONE, :bar, 4
41
+
42
+ => [{ foo: 'a', bar: 4 }, { foo: 'b', bar: 4 }]
43
+
44
+ 3) Return all the available keys from a hash including subset hash
45
+ hash = {"World" => "Region", "Country" => [{"Name" => "India", "Capital" => "Delhi"}, {"Name" => "England", "Capital" => "London"}]}
46
+ => ["World","Country","Name","Capital","Name","Capital"]
26
47
 
27
48
  ## Development
28
49
 
Binary file
@@ -1,3 +1,3 @@
1
1
  module HashMultiTool
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -1,12 +1,28 @@
1
1
  require "hash_multi_tool/version"
2
2
 
3
3
  module HashMultiTool
4
- def self.sort_by_order hash = {}, order = [], direction ='ASC'
5
- hash.sort do |a,b|
6
- a_arr = []
7
- b_arr = []
8
- order.each{|key| a_arr << a[key]; b_arr << b[key];}
9
- direction.downcase == "desc" ? b_arr <=> a_arr : a_arr <=> b_arr
10
- end
11
- end
4
+ class << self
5
+ def sort_by_order hash = {}, order = [], direction ='ASC'
6
+ hash.sort do |a,b|
7
+ a_arr = []
8
+ b_arr = []
9
+ order.each{|key| a_arr << a[key]; b_arr << b[key];}
10
+ direction.downcase == "desc" ? b_arr <=> a_arr : a_arr <=> b_arr
11
+ end
12
+ end
13
+
14
+ def select_by_key_value hash = {}, key = [], value = nil
15
+ hash.select { |h| h[key] == value }
16
+ end
17
+
18
+ def collect_keys(h_object)
19
+ if h_object.is_a? Hash
20
+ (h_object.keys + collect_keys(h_object.values)).flatten.uniq
21
+ elsif h_object.is_a? Array
22
+ h_object.collect{|value| collect_keys value}
23
+ else
24
+ []
25
+ end
26
+ end
27
+ end
12
28
  end
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hash_multi_tool
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2015-04-22 00:00:00.000000000 Z
12
+ date: 2015-04-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -66,19 +66,19 @@ executables: []
66
66
  extensions: []
67
67
  extra_rdoc_files: []
68
68
  files:
69
- - .gitignore
70
- - .rspec
71
- - .travis.yml
72
69
  - CODE_OF_CONDUCT.md
73
70
  - Gemfile
71
+ - Gemfile.lock
74
72
  - LICENSE.txt
75
73
  - README.md
76
74
  - Rakefile
77
75
  - bin/console
78
76
  - bin/setup
77
+ - hash_multi_tool-0.1.0.gem
79
78
  - hash_multi_tool.gemspec
80
79
  - lib/hash_multi_tool.rb
81
80
  - lib/hash_multi_tool/version.rb
81
+ - pkg/hash_multi_tool-0.1.1.gem
82
82
  homepage: https://github.com/prabhat4ever/hash_multi_tool/
83
83
  licenses:
84
84
  - MIT
data/.gitignore DELETED
@@ -1,9 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --format documentation
2
- --color
data/.travis.yml DELETED
@@ -1,3 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 1.9.3