dictionary_order_sort 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/lib/dictionary_order_sort/array.rb +6 -2
- data/lib/dictionary_order_sort/version.rb +1 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -16,7 +16,7 @@ gem 'dictionary_order_sort'
|
|
16
16
|
|
17
17
|
# Usage
|
18
18
|
|
19
|
-
You can now use the `dict_sort` method on
|
19
|
+
You can now use the `dict_sort` method on arrays or sets. Array elements must be strings, or respond to `to_s`.
|
20
20
|
|
21
21
|
Use it like this:
|
22
22
|
|
@@ -1,9 +1,13 @@
|
|
1
1
|
class Array
|
2
|
+
# Sorts an array of strings with 'dictionary sort' logic.
|
3
|
+
# Produces the same order as the Linux command `sort --dictionary-order`.
|
4
|
+
# (Note that `--dictionary-order` is the default order for the `sort` command.)
|
2
5
|
def dict_sort
|
3
6
|
sorting_cache = {}
|
4
7
|
sort do |a, b|
|
5
|
-
c, d = [a, b].map do |
|
6
|
-
|
8
|
+
c, d = [a, b].map do |el|
|
9
|
+
str = el.to_s
|
10
|
+
sorting_cache[str] ||= str.gsub /\W|[_\s]/, ''
|
7
11
|
end
|
8
12
|
c <=> d
|
9
13
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dictionary_order_sort
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -40,7 +40,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
40
40
|
version: '0'
|
41
41
|
segments:
|
42
42
|
- 0
|
43
|
-
hash:
|
43
|
+
hash: 2705371564696453063
|
44
44
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
45
|
none: false
|
46
46
|
requirements:
|
@@ -49,7 +49,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
49
49
|
version: '0'
|
50
50
|
segments:
|
51
51
|
- 0
|
52
|
-
hash:
|
52
|
+
hash: 2705371564696453063
|
53
53
|
requirements: []
|
54
54
|
rubyforge_project:
|
55
55
|
rubygems_version: 1.8.24
|