deepsort 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +8 -8
  2. data/lib/deepsort.rb +10 -23
  3. metadata +3 -2
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NzlkNjkzMTNmY2Q4NDQ4MTY0NTc3MmM3MjNjYmM1NDVjNTJkYTM3NQ==
4
+ MTM1YTQ1NjczOTQ3MDVlYzQzM2E4MjgxYzI3MmI0ZjhiNGRiZjNkMg==
5
5
  data.tar.gz: !binary |-
6
- ZDJkYTVhMTEyM2JjMGEwZTUwNTU1YzYwMTdlMmI0ZWZkYjNiZDdmZg==
6
+ ZDYzMGZiZTRlYjk0ZWQzNTg4Yjg1ODA5NjQ4YzNlZmQ4OWJhZmIxZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NDA5Mzk0OTNkMWE5YjNiMWVmOTdmNmUzMmFjZGMyZmM5ZGRhNjk0ZGM4Y2Iz
10
- NjYzZDYwMDc5MmRlODhhNjBlZTkzNTBhMTBhNThhZmU3YjY1MTk4MjlkYzgz
11
- MWE2YjA2ZGJjOGUyYmFmMmE4MTdjOWZiMjYwZjkwOTEyMDM1YTQ=
9
+ YzM1ZTVhNWE2NzdmY2I0M2VkNTVjNmQyYzBkZWFjNGEyYjFiZGZlOTE2MWNk
10
+ Y2M1ZTVkYzY4ZWVlMDNkZjhhOTM0NTczNWZhNGNiODc4MjE2OTU4NTQ1NTA4
11
+ NDgyOGEwNjViMGIxNWY1MDEwNGIzYzcwZDQ5MDc5ZDRiMDQ5Yzc=
12
12
  data.tar.gz: !binary |-
13
- YTE1MDU2OWZiNmI1OTY3ZGU0ZjlhMWMwYzVhNGQ3OWUwM2Q1YjIxM2JlMzlm
14
- ZDE4ZWNkM2NkODg3NDMxN2QwM2M4YzBhMWZjNWY0ZWQ4MmE1MjhlNTdiNjU1
15
- MWY1MTE1NDY3YjAxNTkzOTUzM2E3ODQ1YTk3ZmVjYmU3MWIyODk=
13
+ NTU1MWVjMTNlOTVlMzI1MzRkZDc5NDhmMzc0YTJiYzMxYjc3MjNjODMwYTdi
14
+ ZjVmYmJlYWE4ZDU2NzBkM2YzZmJhZDA0YWIxNjhkYmJkOTI0NjM2OWJhYmI4
15
+ ZjUyZWZlMWUyMWI5NmE4NTkwMTQ3NDAxNzMzZWY4MDYyYWQ5ZmE=
@@ -28,8 +28,6 @@ module DeepSort
28
28
  self.map do |value|
29
29
  if value.respond_to? :deep_sort_by
30
30
  value.deep_sort_by(&block)
31
- elsif value.respond_to? :sort_by
32
- value.sort_by(&block)
33
31
  else
34
32
  value
35
33
  end
@@ -40,8 +38,6 @@ module DeepSort
40
38
  self.map! do |value|
41
39
  if value.respond_to? :deep_sort_by!
42
40
  value.deep_sort_by!(&block)
43
- elsif value.respond_to? :sort_by!
44
- value.sort_by!(&block)
45
41
  else
46
42
  value
47
43
  end
@@ -50,7 +46,6 @@ module DeepSort
50
46
  end
51
47
 
52
48
  # inject this method into the Hash class to add deep sort functionality to Hashes
53
- # Note: this cannot sort a hashes keys in place (deep_sort!), only the values
54
49
  module DeepSortHash
55
50
  def deep_sort
56
51
  deep_sort_by { |obj| obj }
@@ -64,16 +59,12 @@ module DeepSort
64
59
  Hash[self.map do |key, value|
65
60
  [if key.respond_to? :deep_sort_by
66
61
  key.deep_sort_by(&block)
67
- elsif key.respond_to? :sort_by
68
- key.sort_by(&block)
69
62
  else
70
63
  key
71
64
  end,
72
65
 
73
66
  if value.respond_to? :deep_sort_by
74
67
  value.deep_sort_by(&block)
75
- elsif value.respond_to? :sort_by
76
- value.sort_by(&block)
77
68
  else
78
69
  value
79
70
  end]
@@ -81,25 +72,21 @@ module DeepSort
81
72
  end.sort_by(&block)]
82
73
  end
83
74
 
84
- # Ruby Hashes don't have in-place-modification like map!, each!, or sort!
85
- # that means that this method won't be able to sort the hash keys in place either.
86
- # since Hashes are technically non-sorted key value pairs, this shouldn't be a problem
87
75
  def deep_sort_by!(&block)
88
- Hash[self.map do |key, value|
89
- if key.respond_to? :deep_sort_by!
76
+ replace(Hash[self.map do |key, value|
77
+ [if key.respond_to? :deep_sort_by!
90
78
  key.deep_sort_by!(&block)
91
- elsif key.respond_to? :sort_by!
92
- key.sort_by!(&block)
93
- end
79
+ else
80
+ key
81
+ end,
94
82
 
95
- if value.respond_to? :deep_sort!
83
+ if value.respond_to? :deep_sort_by!
96
84
  value.deep_sort_by!(&block)
97
- elsif value.respond_to? :sort_by!
98
- value.sort_by!(&block)
99
- end
85
+ else
86
+ value
87
+ end]
100
88
 
101
- [key, value]
102
- end]
89
+ end.sort_by(&block)])
103
90
  end
104
91
  end
105
92
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deepsort
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Crossen
@@ -18,7 +18,8 @@ extra_rdoc_files: []
18
18
  files:
19
19
  - lib/deepsort.rb
20
20
  homepage: https://github.com/mcrossen/deepsort
21
- licenses: []
21
+ licenses:
22
+ - MIT
22
23
  metadata: {}
23
24
  post_install_message:
24
25
  rdoc_options: []