dictionary_order_sort 0.1.0
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/MIT-LICENSE +20 -0
- data/README.md +27 -0
- data/Rakefile +28 -0
- data/lib/dictionary_order_sort.rb +1 -0
- data/lib/dictionary_order_sort/array.rb +11 -0
- data/lib/dictionary_order_sort/version.rb +3 -0
- data/test/dict_sort_test.rb +17 -0
- metadata +59 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Nathan D. Broadbent
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# Dictionary Order Sort
|
2
|
+
|
3
|
+
Sorts an array of strings in the same manner as the Linux `sort` command running with the `--dictionary-order` option. Only blanks and alphanumeric characters are considered.
|
4
|
+
|
5
|
+
I created this gem after trying to use the `comm` command in a Capistrano recipe, with the files being sorted in Ruby. `comm` requires the input files to be sorted using the collating sequence specified by `LC_COLLATE', and this defaults to dictionary sort.
|
6
|
+
|
7
|
+
In the end, I just piped the files to the Linux `sort` command, but I decided to write it anyway and release it as a tiny gem.
|
8
|
+
|
9
|
+
# Installation
|
10
|
+
|
11
|
+
Add the following line to your `Gemfile`:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'dictionary_order_sort'
|
15
|
+
```
|
16
|
+
|
17
|
+
# Usage
|
18
|
+
|
19
|
+
You can now use the `dict_sort` method on any arrays. Array elements must be strings, or respond to `to_s`.
|
20
|
+
|
21
|
+
Use it like this:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
["a", "a-2", "_a-3", "abc_", "_def_"].dict_sort
|
25
|
+
|
26
|
+
#=> ["a", "a-2", "_a-3", "abc_", "_def_"]
|
27
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require 'rake/testtask'
|
3
|
+
ENV["TEST_CORES"] = "1"
|
4
|
+
|
5
|
+
require 'bundler'
|
6
|
+
Bundler::GemHelper.install_tasks
|
7
|
+
|
8
|
+
namespace :test do
|
9
|
+
task :isolated do
|
10
|
+
Dir["test/assets*_test.rb"].each do |file|
|
11
|
+
dash_i = [
|
12
|
+
'test',
|
13
|
+
'lib',
|
14
|
+
]
|
15
|
+
ruby "-I#{dash_i.join ':'}", file
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
Rake::TestTask.new("test:regular") do |t|
|
21
|
+
t.libs << 'lib'
|
22
|
+
t.libs << 'test'
|
23
|
+
t.pattern = 'test/**/sprockets*_test.rb'
|
24
|
+
t.verbose = true
|
25
|
+
end
|
26
|
+
|
27
|
+
task :test => ['test:isolated', 'test:regular']
|
28
|
+
task :default => :test
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'dictionary_order_sort/array'
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'minitest/autorun'
|
5
|
+
|
6
|
+
require 'dictionary_order_sort'
|
7
|
+
|
8
|
+
class TestArrayDictSort < MiniTest::Unit::TestCase
|
9
|
+
def test_dict_sort
|
10
|
+
arr = ['a', 'a-2', '_a-3', 'abc_', '_def_', 'b', 'ce', 'd_a', '-b_', '___b']
|
11
|
+
|
12
|
+
system_sort = `echo #{arr.join("\\\\n")} | sort`.split
|
13
|
+
ruby_sort = arr.dict_sort
|
14
|
+
|
15
|
+
assert_equal ruby_sort, system_sort
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dictionary_order_sort
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Nathan Broadbent
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-30 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Sort an array in the same order as `sort --dictionary-sort`
|
15
|
+
email:
|
16
|
+
- nathan.f77@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/dictionary_order_sort.rb
|
22
|
+
- lib/dictionary_order_sort/array.rb
|
23
|
+
- lib/dictionary_order_sort/version.rb
|
24
|
+
- MIT-LICENSE
|
25
|
+
- Rakefile
|
26
|
+
- README.md
|
27
|
+
- test/dict_sort_test.rb
|
28
|
+
homepage: https://github.com/ndbroadbent/dictionary_order_sort
|
29
|
+
licenses: []
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
segments:
|
41
|
+
- 0
|
42
|
+
hash: -4262464269304816571
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
segments:
|
50
|
+
- 0
|
51
|
+
hash: -4262464269304816571
|
52
|
+
requirements: []
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 1.8.24
|
55
|
+
signing_key:
|
56
|
+
specification_version: 3
|
57
|
+
summary: --dictionary-sort for Ruby arrays
|
58
|
+
test_files:
|
59
|
+
- test/dict_sort_test.rb
|