vilango-sort_alphabetical 0.0.3

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,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vilango-sort_alphabetical
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 3
10
+ version: 0.0.3
11
+ platform: ruby
12
+ authors:
13
+ - Michael Grosser
14
+ - Gerwin Brunner
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2010-07-02 00:00:00 +02:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: activesupport
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ description:
37
+ email: gerwin (dot) brunner (at) gmail (dot) com
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files: []
43
+
44
+ files:
45
+ - VERSION.yml
46
+ - README.markdown
47
+ - lib/sort_alphabetical.rb
48
+ - lib/sort_alphabetical/core_ext.rb
49
+ - spec/spec_helper.rb
50
+ - spec/README.markdown
51
+ - spec/sort_alphabetical_spec.rb
52
+ has_rdoc: true
53
+ homepage: http://github.com/gerwinbrunner/sort_alphabetical
54
+ licenses: []
55
+
56
+ post_install_message:
57
+ rdoc_options:
58
+ - --inline-source
59
+ - --charset=UTF-8
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ hash: 3
68
+ segments:
69
+ - 0
70
+ version: "0"
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 3
77
+ segments:
78
+ - 0
79
+ version: "0"
80
+ requirements: []
81
+
82
+ rubyforge_project:
83
+ rubygems_version: 1.3.7
84
+ signing_key:
85
+ specification_version: 2
86
+ summary: Sort UTF8 Strings alphabetical via Enumerable extension
87
+ test_files: []
88
+