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 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 any arrays. Array elements must be strings, or respond to `to_s`.
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 |f|
6
- sorting_cache[f] ||= f.gsub /\W|[_\s]/, ''
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
@@ -1,3 +1,3 @@
1
1
  module DictionaryOrderSort
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  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.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: -2472803673037020292
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: -2472803673037020292
52
+ hash: 2705371564696453063
53
53
  requirements: []
54
54
  rubyforge_project:
55
55
  rubygems_version: 1.8.24