a-b-chi 1.1.3 → 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NTVjMTRmMGE5YmYzZTllN2VhZWMyMWQ4YTAwOGU4MGQyMzM3YjEwYQ==
4
+ NTk2NDI4YjNjYTZhZTE4ZWExODgwOGU4MjAwZGY2MDAxMmUyZWQzYw==
5
5
  data.tar.gz: !binary |-
6
- YmRkODY5Y2NjMDI1YmJmMTM2ZjAyYWZhZjgyNGVjMzEzOTMxNTJjYg==
6
+ MzAyYzRlYzdjYjExMGQ4ZTQ0M2U5MjQ1NTg4ZmNhNmE0ZDZlMWFkOQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZGU1MzBmNDA2MzRhMDM1YmQxYzVmNjQ3OGFjMGZhNzQ4ZGI4M2ExN2Q1N2Qx
10
- NTlhNDQ0MDVkNTcwMDliNzg2MjIzZWI1ZTc2Y2NjYmMxZTMyNTlkNTNiYzM2
11
- ODFkYTFjODcyODcyNzk4NzFlNGUyMDU4ZGQwOTU3YzYwY2ZhMGI=
9
+ ZTMwZGZlYmY3MjNlZGZmYzkwMzEwNTc3MzVlYTFkNzc2YmM3NzQ4ZmUyMTk1
10
+ Zjg5NDY2ZTNiN2RkNmY3NjQxNTExMzQ3MmUxYzZkMDRlNjk0ODg3MjU1YTU4
11
+ NTc5YjFlMDlkNzAyNTUwZjU3NzJmZjFkNDllYmM2ODdiMTUzOTY=
12
12
  data.tar.gz: !binary |-
13
- NjE0ZjRlYmMxNzhjNDdlNWQ4MWU3ZTIyZWFhMDg2MDYyMmU4N2ZmNWIwMzQ0
14
- ODU1YWY2MjMyZDhmNjhhYzcyMjMyZTFjOTA4Njk0ZTU4NDhkYjJjOTYwOThm
15
- ZGY1MGI3MTIzMzQyZDNlNjZlMjJhOTUyYjk5MmYwOTdmYWEyM2I=
13
+ ZDg2YzU4OWEzYWFjM2U2ZmFkY2E0OGUyYWJkYzZhY2NiOTU2YjhkOTdlMjY1
14
+ MmJiMjRjYTk5M2ZjYmRkMTBjZjlhYTcyMDQ5Nzk5OTYxNzAxMWRjYTZhMGIz
15
+ OGQ3MTYyNzk1MDI3MzFkNjRmYzVhN2I1NDk2YTViN2YxYmZiY2U=
@@ -0,0 +1,55 @@
1
+ A-B-Chi
2
+ =========
3
+ In the Morning!
4
+
5
+ A-B-Chi is a RubyGem aimed at making the process of sorting Chinese Traditional characters easy without having to change database collation settings (I personally couldnt work them out).
6
+
7
+ I have been wroking in Taiwan for the last year on a CRM-type database and have learned quite a bit about Chinese Traditional characters and their attributes. after pulling my hair out over collation I decided that the best thing to do would be to make my own solution and as I notice that a lot of other people have similar problems I wanted to make this publically available.
8
+
9
+
10
+ There are a few extra functions that I plan to implement in the future which include
11
+
12
+ - Character to BoPoMoFo (pronunciation characters) and other various things - perhaps a ruby text function or two.
13
+ - Handling of English and Chinese Simplified Characters.
14
+ - Base everything around the utf-8 character codes rather than a list of characters.
15
+
16
+ Version
17
+ -
18
+
19
+ 1.1.3
20
+
21
+ Further Info
22
+ -----------
23
+ - I have compiled an extensive database of each Chinese Traditional character and its attributes indluding each different pronunciation of it and will be implementing this in awesome ways in the future. This contains just shy of 16,000 entries.
24
+
25
+ - If you want to know about BoPoMoFo, I recommend reading the Wikipedia entry on it: http://en.wikipedia.org/wiki/Bopomofo
26
+
27
+ - You should also check out the Taiwan Government's official write-up on their standards which can be found here: http://www.cns11643.gov.tw/AIDB/encodings_en.do
28
+
29
+
30
+ Installation
31
+ --------------
32
+
33
+ ```gem install a-b-chi```
34
+ or for bundler add the following to your Gemfile
35
+ ```gem 'a-b-chi'```
36
+
37
+ The sourcecode can be found at https://github.com/nallan/a-b-chi
38
+
39
+ Usage
40
+ --------------
41
+
42
+ firstly require the file in your project
43
+ ```require 'a-b-chi'```
44
+ next you must create a new instance of the ArrayChinese class and populate your array
45
+ ```arr = ArrayChinese.new
46
+ arr.push "李依恬", "李雲帆", "珍項小珍", "瑞芳", "李宗翰"
47
+ ```
48
+ finally run the sort method on this. both sort and sort! are supported
49
+ ```arr.sort
50
+ arr.sort!```
51
+
52
+ License
53
+ -
54
+
55
+ MIT
@@ -0,0 +1,8 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ end
6
+
7
+ desc "Run tests"
8
+ task :default => :test
@@ -1,34 +1,39 @@
1
1
  #encoding:utf-8
2
2
 
3
3
  class ArrayChinese < Array
4
+ alias array_sort sort
5
+ alias array_sort_by sort_by
6
+ alias array_sort_by! sort_by!
4
7
 
5
8
  def initialize
6
9
  spec = Gem::Specification.find_by_name("a-b-chi")
7
10
  gem_root = spec.gem_dir
8
11
  gem_lib = gem_root + "/lib"
9
12
  @characters = File.read("#{gem_lib}/characters.txt").split("\n")
10
-
11
13
  end
12
14
 
13
15
  def sort
14
- max_length = self.max_by(&:length).length
15
- search_query = '['
16
- for i in 0..max_length
17
- unless i == max_length
18
- search_query << "@characters.index(sort_string[#{i}]), "
19
- else
20
- search_query << "@characters.index(sort_string[#{i}])]"
21
- end
22
- end
23
- self.sort_by! { |sort_string| eval(search_query) }
16
+ self.array_sort_by { |sort_string| eval(get_sort_query) }
24
17
  end
25
18
 
26
- end
19
+ def sort!
20
+ self.array_sort_by! { |sort_string| eval(get_sort_query) }
21
+ end
27
22
 
28
- class BoPoMoFo < String
29
-
30
- def initialize
31
-
23
+ # def sort_by(*args)
24
+ # puts args.inspect
25
+ # self.array_sort_by! { |sort_string| eval(get_sort_query) }
26
+ # end
27
+
28
+ private
29
+
30
+ def get_sort_query
31
+ max_length = self.max_by(&:length).length
32
+ sort_query = '['
33
+ (0..max_length).each { |i| sort_query << " @characters.index(sort_string[#{i}])," }
34
+ sort_query.chop!
35
+ sort_query << ']'
36
+ return sort_query
32
37
  end
33
-
38
+
34
39
  end
@@ -0,0 +1,35 @@
1
+ #encoding: utf-8
2
+
3
+ require 'test/unit'
4
+ require 'a-b-chi'
5
+
6
+ class ABChiTest < Test::Unit::TestCase
7
+
8
+ def test_string_sort
9
+ arr = ArrayChinese.new
10
+ arr.push "李依恬", "李雲帆", "珍項小珍", "瑞芳", "李宗翰", "李彩雲", "李璨亘", "李若喬", "李瑞雰", "李彩喬", "李素霞", "李依帆", "NallaN", "彩依恬", "彩雲恬", "雲李", "雲則欣", "雲彩雲"
11
+ assert_equal ["李若喬", "李瑞雰", "李宗翰", "李彩喬", "李彩雲", "李璨亘", "李素霞", "李依帆", "李依恬", "李雲帆", "珍項小珍", "瑞芳", "彩依恬", "彩雲恬", "雲李", "雲則欣", "雲彩雲", "NallaN"],
12
+ arr.sort
13
+ end
14
+
15
+ def test_blank_array
16
+ arr = ArrayChinese.new
17
+ arr.push
18
+ assert_equal [], arr.sort
19
+ end
20
+
21
+ def test_english_after_chinese
22
+ arr = ArrayChinese.new
23
+ arr.push "雲Z雲", "NallaN", "雲彩雲"
24
+ assert_equal ["雲彩雲", "雲Z雲", "NallaN"],
25
+ arr.sort
26
+ end
27
+
28
+ def test_handling_of_unknown_characters
29
+ arr = ArrayChinese.new
30
+ arr.push "Z∂ß", "NallaN", "雲彩雲"
31
+ assert_equal ["雲彩雲", "NallaN", "Z∂ß"],
32
+ arr.sort
33
+ end
34
+
35
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: a-b-chi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathanial Allan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-07 00:00:00.000000000 Z
11
+ date: 2013-08-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A gem that allows for the user to sort Chinese Traditional characters
14
14
  like a human (phonetically) rather than like a robot (stroke count)
@@ -17,15 +17,16 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
+ - Rakefile
21
+ - README.md
20
22
  - lib/a-b-chi.rb
21
23
  - lib/characters.txt
24
+ - test/test_a-b-chi.rb
22
25
  homepage: http://rubygems.org/gems/a-b-chi
23
26
  licenses:
24
27
  - MIT
25
28
  metadata: {}
26
- post_install_message: ! 'In The Morning to you! - I hope this makes your life easier!
27
-
28
- '
29
+ post_install_message: ITM!
29
30
  rdoc_options: []
30
31
  require_paths:
31
32
  - lib