gerwinbrunner-sort_alphabetical 0.0.2

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/README.markdown ADDED
@@ -0,0 +1,23 @@
1
+ Adds `sort_alphabetical` and `sort_alphabetical_by` to Enumberable(Array/Hash...),
2
+ which sorts UTF8 Strings alphabetical.
3
+ This sorting is done by placing variants on the same level as base character (A comes before Ä but ÄA comes before AB).
4
+
5
+ ['b','á'].sort_alphabetical == ['á','b']
6
+ [['b',1],['á',2]].sort_alphabetical_by(&:first) == [['á',2],['b',1]]
7
+
8
+ Setup
9
+ =====
10
+ sudo gem install grosser-sort_alphabetical -s http://gems.github.com/
11
+
12
+ TODO
13
+ ====
14
+ - Sort non-ascii-convertables like ß(ss), œ(oe) , fi(fi), see [Ligatures](http://en.wikipedia.org/wiki/Typographical_ligature)
15
+ - Integrate natural sorting e.g. `['a11', 'a2'] => ['a2', 'a11']` like [NaturalSort](http://rubyforge.org/projects/naturalsort)
16
+
17
+ Authors
18
+ =======
19
+ - original string_to_ascii: [Marc-Andre](http://marc-andre.ca/).
20
+
21
+ [Michael Grosser](http://pragmatig.wordpress.com)
22
+ grosser.michael@gmail.com
23
+ Hereby placed under public domain, do what you want, just do not hold me accountable...
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :minor: 0
3
+ :patch: 1
4
+ :major: 0
@@ -0,0 +1,33 @@
1
+ require 'rubygems'
2
+ require 'active_support'
3
+ require 'sort_alphabetical/core_ext'
4
+
5
+ module SortAlphabetical
6
+ extend self
7
+
8
+ def sort(set)
9
+ set.sort_by do |item|
10
+ if block_given?
11
+ item = yield(item).to_s
12
+ else
13
+ item = item.to_s
14
+ end
15
+ [to_ascii(item),item]#when both á and a are present, sort them a, á
16
+ end
17
+ end
18
+
19
+ def to_ascii(string)
20
+ split_codepoints(string).map(&:to_s).reject{|e| e.length > 1}.join
21
+ end
22
+
23
+ private
24
+
25
+ # returns an array of unicode codepoints, in canonical order
26
+ def split_codepoints(string)
27
+ if defined? ActiveSupport::Multibyte::Handlers #pre ActiveSupport 2.3
28
+ ActiveSupport::Multibyte::Handlers::UTF8Handler.normalize(string,:d).split(//u)
29
+ else
30
+ string.mb_chars.normalize(:d).split(//u)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,9 @@
1
+ module Enumerable
2
+ def sort_alphabetical
3
+ SortAlphabetical.sort(self)
4
+ end
5
+
6
+ def sort_alphabetical_by(&block)
7
+ SortAlphabetical.sort(self,&block)
8
+ end
9
+ end
@@ -0,0 +1,2 @@
1
+ Autotest will not work here, since both activesupport 2.1.1 and 2.3 are tested for individually.
2
+ Simply run `rake`
@@ -0,0 +1,43 @@
1
+ if version = ENV['ACTIVE_SUPPORT_VERSION']
2
+ gem 'activesupport', version
3
+ version = "(AS: #{version})"
4
+ else
5
+ gem 'activesupport', '>=2.3'
6
+ end
7
+ require File.expand_path("spec_helper", File.dirname(__FILE__))
8
+
9
+ describe "SortAlphabetical #{version}"do
10
+ it "sorts ascii correctly" do
11
+ %w(b c a).sort_alphabetical.should == %w(a b c)
12
+ end
13
+
14
+ it "sorts UTF8 chars without accents" do
15
+ %w(b a á ä o ó x ö í i c).sort_alphabetical.should == %w(a á ä b c i í o ó ö x)
16
+ end
17
+
18
+ it "sorts by merging base with accented" do
19
+ %w(AA AB ÄA).sort_alphabetical.should == %w(AA ÄA AB)
20
+ end
21
+
22
+ it "sorts words" do
23
+ %w(hellö hello hellá).sort_alphabetical.should == %w(hellá hello hellö)
24
+ end
25
+
26
+ pending_it "obeys order for ligatures" do
27
+ %w(asb aßc asd).sort_alphabetical.should == %w(asb aßc asd)
28
+ end
29
+
30
+ describe :to_ascii do
31
+ it "removes any accents" do
32
+ SortAlphabetical.to_ascii('á').should == 'a'
33
+ end
34
+ end
35
+
36
+ describe :sort_alphabetical_by do
37
+ it "sorts using given block" do
38
+ silence_warnings do
39
+ %w(za yá xä xa).sort_alphabetical_by{|x|x.chars.to_a.reverse.join}.should == %w(xa xä yá za)
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,10 @@
1
+ # ---- requirements
2
+ $LOAD_PATH.unshift File.expand_path("../lib", File.dirname(__FILE__))
3
+ require 'sort_alphabetical'
4
+
5
+ # ---- Helpers
6
+ def pending_it(text,&block)
7
+ it text do
8
+ pending(&block)
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gerwinbrunner-sort_alphabetical
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Michael Grosser
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-03-18 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activesupport
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description:
26
+ email: grosser.michael@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - VERSION.yml
35
+ - README.markdown
36
+ - lib/sort_alphabetical.rb
37
+ - lib/sort_alphabetical
38
+ - lib/sort_alphabetical/core_ext.rb
39
+ - spec/spec_helper.rb
40
+ - spec/README.markdown
41
+ - spec/sort_alphabetical_spec.rb
42
+ has_rdoc: true
43
+ homepage: http://github.com/grosser/sort_alphabetical
44
+ licenses:
45
+ post_install_message:
46
+ rdoc_options:
47
+ - --inline-source
48
+ - --charset=UTF-8
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ requirements: []
64
+
65
+ rubyforge_project:
66
+ rubygems_version: 1.3.5
67
+ signing_key:
68
+ specification_version: 2
69
+ summary: Sort UTF8 Strings alphabetical via Enumerable extension
70
+ test_files: []
71
+