string_to_pinyin 1.0.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.
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+ class String
3
+
4
+ def to_pinyin
5
+ idx_file_path = File.expand_path('../../data/idx99-tone.txt',__FILE__)
6
+ result = ""
7
+ self.scan(/./) do |char|
8
+ match = %x[grep -m1 '^#{char}' #{idx_file_path}]
9
+ if match.empty?
10
+ result = result + char
11
+ else
12
+ pinyin = match.gsub("\n","").split("\t")[1]
13
+ result = result + pinyin + " "
14
+ end
15
+ end
16
+ return result.rstrip
17
+ end
18
+
19
+ end
Binary file
Binary file
Binary file
data/spec/spec.opts ADDED
@@ -0,0 +1,5 @@
1
+ --color
2
+ --format progress
3
+ --loadby mtime
4
+ --reverse
5
+
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+ require 'string_to_pinyin'
5
+ require 'spec'
6
+ require 'spec/autorun'
7
+
8
+ Spec::Runner.configure do |config|
9
+
10
+ end
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
+
4
+ describe "StringToPinyin" do
5
+ before :each do
6
+ @single_char = "名"
7
+ @multiple_chars = "中华人民共和国"
8
+ @nil_char = "a"
9
+ @punctuated = "你好! 你是中国人吗? <- that was mandarin"
10
+ end
11
+
12
+ it "should return pinyin for a single character if found" do
13
+ @single_char.to_pinyin.should == 'míng'
14
+ end
15
+
16
+ it "should return pinyin with spaces in between for multiple characters if found" do
17
+ @multiple_chars.to_pinyin.should == 'zhōng huá rén mín gòng hé guó'
18
+ end
19
+
20
+ it "should return a character if its not found in the index" do
21
+ @nil_char.to_pinyin.should == 'a'
22
+ end
23
+
24
+ it "should return 'non-simplified chinese characters' as they are" do
25
+ @punctuated.to_pinyin.should == 'nĭ hăo ! nĭ shì zhōng guó rén ma ? <- that was mandarin'
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: string_to_pinyin
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Toritaba
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-06-30 00:00:00 +05:30
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 13
30
+ segments:
31
+ - 1
32
+ - 2
33
+ - 9
34
+ version: 1.2.9
35
+ type: :development
36
+ version_requirements: *id001
37
+ description: Adds a 'to_pinyin' method to Ruby's String class to convert Simplified Chinese characters to Hanyu Pinyin
38
+ email: toritaba@gmail.com
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files:
44
+ - LICENSE
45
+ - README
46
+ files:
47
+ - .gitignore
48
+ - CHANGELOG
49
+ - CREDITS
50
+ - LICENSE
51
+ - README
52
+ - Rakefile
53
+ - VERSION
54
+ - data/idx99-tone.txt
55
+ - lib/string_to_pinyin.rb
56
+ - pkg/string_to_pinyin-0.1.0.gem
57
+ - pkg/string_to_pinyin-0.1.1.gem
58
+ - pkg/string_to_pinyin-0.2.0.gem
59
+ - spec/spec.opts
60
+ - spec/spec_helper.rb
61
+ - spec/string_to_pinyin_spec.rb
62
+ has_rdoc: true
63
+ homepage: http://github.com/toritaba/string_to_pinyin
64
+ licenses: []
65
+
66
+ post_install_message:
67
+ rdoc_options:
68
+ - --charset=UTF-8
69
+ require_paths:
70
+ - lib
71
+ required_ruby_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
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ hash: 3
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ requirements: []
90
+
91
+ rubyforge_project:
92
+ rubygems_version: 1.3.7
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: Converts Simplified Chinese characters to pinyin
96
+ test_files:
97
+ - spec/string_to_pinyin_spec.rb
98
+ - spec/spec_helper.rb