hash_multi_tool 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 203eaabf0157c628c4e1c7a8a906a32c7ced1e0f
4
+ data.tar.gz: f83760be42ec8f7e3154b15a0f78855d15846261
5
+ SHA512:
6
+ metadata.gz: 5d0c32d1e8d8c5750a2a704885a02bdc052d41626982b8b6fdd814d702726eff9de7bdb27165a0a662b813d2d97213d8bf647b87fa11f417fdf4289434894499
7
+ data.tar.gz: 099d432fd2b5ddb24f9b91b36a32b1784e91d1de8d4646b225d187bf8ddc759f29de4f445868e94c9557a545eb071c94e680bbe33840552c975ef3df20eda491
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hash_multi_tool (0.1.1)
4
+ hash_multi_tool (0.1.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -25,3 +25,6 @@ DEPENDENCIES
25
25
  hash_multi_tool!
26
26
  rake (~> 10.0)
27
27
  rspec
28
+
29
+ BUNDLED WITH
30
+ 1.10.5
data/README.md CHANGED
@@ -41,29 +41,48 @@ Or install it yourself as:
41
41
 
42
42
  => [{ foo: 'a', bar: 4 }, { foo: 'b', bar: 4 }]
43
43
 
44
- 3) Return all the available keys from a hash including subset hash :-
45
-
46
- hash = {"World" => "Region", "Country" => [{"Name" => "India", "Capital" => "Delhi"}, {"Name" => "England", "Capital" => "London"}]}
47
- hash_keys = HashMultiTool.collect_keys hash
48
- => ["World","Country","Name","Capital","Name","Capital"]
49
-
50
- hash_keys.uniq
51
- => ["World","Country","Name","Capital"]
52
-
53
- 4) Merge the keys and with collected values belongs to respective keys and return a single hash
54
- arr = [{a:1, b:2, c:3},{a:1, b:2, c:3},{a:1, b:2, c:3},{a:1, b:2}]
44
+ 3) Return all the available keys from a hash including subset hash :-
45
+
46
+ hash = {"World" => "Region", "Country" => [{"Name" => "India", "Capital" => "Delhi"}, {"Name" => "England", "Capital" => "London"}]}
47
+ hash_keys = HashMultiTool.collect_keys hash
48
+ => ["World","Country","Name","Capital","Name","Capital"]
49
+
50
+ hash_keys.uniq
51
+ => ["World","Country","Name","Capital"]
52
+
53
+ 4) Merge the keys and with collected values belongs to respective keys and return a single hash
54
+
55
+ arr = [{a:1, b:2, c:3},{a:1, b:2, c:3},{a:1, b:2, c:3},{a:1, b:2}]
55
56
 
56
- hash_keys = HashMultiTool.transpose_to_hash arr
57
+ hash_keys = HashMultiTool.transpose_to_hash arr
57
58
 
58
- => {:a=>[1, 1, 1, 1], :b=>[2, 2, 2, 2], :c=>[3, 3, 3]}
59
+ => {:a=>[1, 1, 1, 1], :b=>[2, 2, 2, 2], :c=>[3, 3, 3]}
59
60
 
60
- 5) Return a collection of keys differentiated with values
61
- hash = {:a=>[1, 1, 1, 1], :b=>[2, 2, 2, 2], :c=>[3, 3, 3]}
61
+ 5) Return a collection of keys differentiated with values
62
+
63
+ hash = {:a=>[1, 1, 1, 1], :b=>[2, 2, 2, 2], :c=>[3, 3, 3]}
62
64
 
63
- hash_keys = HashMultiTool.transpose_to_array hash
65
+ hash_keys = HashMultiTool.transpose_to_array hash
64
66
 
65
- => [{a:1, b:2, c:3},{a:1, b:2, c:3},{a:1, b:2, c:3},{a:1, b:2}]
66
-
67
+ => [{a:1, b:2, c:3},{a:1, b:2, c:3},{a:1, b:2, c:3},{a:1, b:2}]
68
+
69
+ 6) Sort a hash by value in ascending order:
70
+
71
+ hash = {a: 1000, b: 500, c: 1500}
72
+
73
+ HashMultiTool.sort_asc hash
74
+
75
+ => {:a=>500, :b=>1000, :c=>1500}
76
+
77
+ 7) Sort a hash by value in descending order:
78
+
79
+ hash = {a: 1000, b: 500, c: 1500}
80
+
81
+ HashMultiTool.sort_desc hash
82
+
83
+ => {:c=>1500, :b=>1000, :a=>500}
84
+
85
+
67
86
  ## Development
68
87
 
69
88
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
Binary file
@@ -38,5 +38,13 @@ module HashMultiTool
38
38
  a
39
39
  }
40
40
  end
41
+
42
+ def sort_desc hash
43
+ Hash[hash.sort_by {|k, v| -v}]
44
+ end
45
+
46
+ def sort_asc hash
47
+ Hash[hash.sort_by {|k, v| v}]
48
+ end
41
49
  end
42
50
  end
@@ -1,3 +1,3 @@
1
1
  module HashMultiTool
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,62 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hash_multi_tool
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
5
- prerelease:
4
+ version: 0.1.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - Prabhat Thapa
9
8
  autorequire:
10
9
  bindir: exe
11
10
  cert_chain: []
12
- date: 2015-06-03 00:00:00.000000000 Z
11
+ date: 2015-07-08 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
19
  version: '1.9'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
26
  version: '1.9'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
33
  version: '10.0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ~>
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
40
  version: '10.0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rspec
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  description: Sort a array of hashes with one or multiple values
@@ -76,6 +69,7 @@ files:
76
69
  - bin/setup
77
70
  - hash_multi_tool-0.1.0.gem
78
71
  - hash_multi_tool-0.1.1.gem
72
+ - hash_multi_tool-0.1.2.gem
79
73
  - hash_multi_tool.gemspec
80
74
  - lib/hash_multi_tool.rb
81
75
  - lib/hash_multi_tool/version.rb
@@ -83,26 +77,26 @@ files:
83
77
  homepage: https://github.com/prabhat4ever/hash_multi_tool/
84
78
  licenses:
85
79
  - MIT
80
+ metadata:
81
+ allowed_push_host: http://mygemserver.com
86
82
  post_install_message:
87
83
  rdoc_options: []
88
84
  require_paths:
89
85
  - lib
90
86
  required_ruby_version: !ruby/object:Gem::Requirement
91
- none: false
92
87
  requirements:
93
- - - ! '>='
88
+ - - ">="
94
89
  - !ruby/object:Gem::Version
95
90
  version: '0'
96
91
  required_rubygems_version: !ruby/object:Gem::Requirement
97
- none: false
98
92
  requirements:
99
- - - ! '>='
93
+ - - ">="
100
94
  - !ruby/object:Gem::Version
101
95
  version: '0'
102
96
  requirements: []
103
97
  rubyforge_project:
104
- rubygems_version: 1.8.23.2
98
+ rubygems_version: 2.4.5
105
99
  signing_key:
106
- specification_version: 3
100
+ specification_version: 4
107
101
  summary: Sort a array of hashes with one or multiple values
108
102
  test_files: []