asian_character 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.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ N2Y0ZDI2ODU3NjMzZGExNDRlNjI1NWNjM2ViNzk5MWViMjI5MTFkMg==
5
+ data.tar.gz: !binary |-
6
+ MTU1NzMxMzY4MmRhODI3YjFmNWZjZTE3ZWY5OTRlNDNjMDhhNjE1Yw==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ N2ZjNmQ0ODg0YmU1ZDUzYzQ1NGIxMTA5OWM4ZGM0NTc2OWMwZWJlYmE1YjNh
10
+ MzUyNjg0OWYwOGMyY2Y2ZjViMjFiYTBjMzUyYTFlY2FlY2QzMzIzYjljMzcz
11
+ YTY3ZWEyM2QzOGYzMzIxNDhlYjA1MTg0YTA0NDQ5NDJkOGI1Nzg=
12
+ data.tar.gz: !binary |-
13
+ Nzc2YTA2ODljZDk3ZTE1NjdlZmNiNzc0MTE5Mzg0MjIwMWUxNjlmM2UzMjk3
14
+ NmQyZTFkNmQwMTJjMjYwZTFlMTQ3YmI3Njg3NjMwZjY0ZGJmMzEyZmRmNTMy
15
+ NTkyZTViYjJkOWIzMjkwMDI5ZGQwZGY3NDIxOTdhNzBlOTZjNzY=
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in asian_character.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Dmitry Mozzherin
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # AsianCharacter
2
+
3
+ This gem provides prononciation and pinyin transcription for Chinese characters
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'asian_character'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install asian_character
18
+
19
+ ## Usage
20
+
21
+ require 'asian_character'
22
+
23
+ word = AsianCharacter::Word.new('谢谢')
24
+
25
+ #to get pinyin transcription
26
+ pinyin = word.pinyin #returns xie4xie4
27
+
28
+ #to get a url to mp3 audio sound
29
+ audio_url = word.sound_url
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'asian_character/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "asian_character"
8
+ spec.version = AsianCharacter::VERSION
9
+ spec.authors = ["Jiangning Wang"]
10
+ spec.email = ["wangjn1982@163.com"]
11
+ spec.description = %q{Provides some functions of Chinese}
12
+ spec.summary = %q{Provides some functions of Chinese}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "rest-client", "~> 1.6"
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "rake", "~> 10.1"
24
+ spec.add_development_dependency "rspec", "~> 2.14"
25
+ spec.add_development_dependency "webmock", "~> 1.13"
26
+ spec.add_development_dependency "debugger", "~> 1.6"
27
+ end
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'autospec' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rspec-core', 'autospec')
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'htmldiff' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('diff-lcs', 'htmldiff')
data/bundle_bin/ldiff ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'ldiff' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('diff-lcs', 'ldiff')
data/bundle_bin/rake ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rake' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rake', 'rake')
data/bundle_bin/rdebug ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rdebug' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('debugger', 'rdebug')
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'restclient' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rest-client', 'restclient')
data/bundle_bin/rspec ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rspec' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rspec-core', 'rspec')
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'sinatra'
4
+ require 'rest_client'
5
+ get '/' do
6
+ haml :home
7
+ end
8
+
9
+ post '/pinyin' do
10
+ @chars = params[:characters]
11
+ res = RestClient.get('http://chinese.biodinfo.org/ChineseCharactorWebService.asmx/GetWordPinyin?word=' + URI.escape(@chars) + '&psd=1')
12
+ res=res.match(/>([a-z0-9]+)<\/string>/)
13
+ @pinyin = res ? res[1] : nil
14
+ haml :pinyin
15
+ end
16
+
17
+ post '/audio' do
18
+ @chars = params[:characters]
19
+ res = RestClient.get('http://chinese.biodinfo.org/ChineseCharactorWebService.asmx/GetWordPinyinSoundMP3?word=' + URI.escape(@chars) + '&psd=1')
20
+ res=res.match(/>(.+)<\/string>/)
21
+ @audio = res ? res[1] : nil
22
+ haml :audio
23
+ end
24
+
25
+ __END__
26
+
27
+ @@layout
28
+ !!!
29
+ %html
30
+ %head
31
+ %title
32
+ just a try
33
+ %body
34
+ = yield
35
+ %p this is footer
36
+
37
+ @@home
38
+ %div pinyin
39
+ %form{ action: :pinyin, method: :post }
40
+ %input{ type: 'text', id: 'characters', name: 'characters' }
41
+ %input{ type: 'submit' }
42
+
43
+ %div Audio
44
+ %form{ action: :audio, method: :post }
45
+ %input{ type: 'text', id: 'characters', name: 'characters' }
46
+ %input{ type: 'submit' }
47
+
48
+ @@pinyin
49
+ %p
50
+ pinyin will be here:
51
+ = @chars
52
+ %p pinyin: #{@pinyin}
53
+
54
+ @@audio
55
+ %p
56
+ Audio will be here:
57
+ =@chars
58
+ %audio{controls: true}
59
+ %source{src: @audio}
@@ -0,0 +1,3 @@
1
+ module AsianCharacter
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,42 @@
1
+ module AsianCharacter
2
+ class Word
3
+ attr_reader :cache
4
+
5
+ def initialize(word)
6
+ @word = word
7
+ @cache = false
8
+ end
9
+
10
+ def pinyin
11
+ if @pinyin
12
+ @cache= true
13
+ return @pinyin
14
+ end
15
+ @cache = false
16
+ url = 'http://chinese.biodinfo.org/'\
17
+ 'ChineseCharactorWebService.asmx/'\
18
+ 'GetWordPinyin?word=' +
19
+ URI.escape(@word) + '&psd=1'
20
+ res = RestClient.get(url)
21
+ res.gsub!(/\s/, ' ')
22
+ res=res.match(%r|<string.*>([a-z0-9]+)</string>|)
23
+ @pinyin = res ? res[1].strip : nil
24
+ end
25
+
26
+ def sound_url
27
+ if @sound_url
28
+ @cache = true
29
+ return @sound_url
30
+ end
31
+ @cache = false
32
+ url = 'http://chinese.biodinfo.org/'\
33
+ 'ChineseCharactorWebService.asmx/'\
34
+ 'GetWordPinyinSoundMP3?word=' +
35
+ URI.escape(@word) + '&psd=1'
36
+ res = RestClient.get(url)
37
+ res.gsub!(/\s/, ' ')
38
+ res=res.match(%r|<string.*>\s*(.+)\s*</string>|)
39
+ @sound_url = res ? res[1].strip : nil
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,7 @@
1
+ require 'rest_client'
2
+ require "asian_character/version"
3
+ require "asian_character/word"
4
+
5
+ module AsianCharacter
6
+
7
+ end
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+ require_relative 'spec_helper'
3
+
4
+ describe "AsianCharacter" do
5
+ it 'is a module' do
6
+ expect(AsianCharacter.respond_to?(:initialize)).to be_false
7
+ end
8
+ end
9
+
@@ -0,0 +1 @@
1
+ <string xmlns="http://chinese.biodinfo.org/">er4</string>
@@ -0,0 +1,3 @@
1
+ <string xmlns="http://chinese.biodinfo.org/">
2
+ http://chinese.biodinfo.org/chinesefiles/soundci/4E8C.mp3
3
+ </string>
@@ -0,0 +1,5 @@
1
+ require 'rspec'
2
+ require 'webmock/rspec'
3
+
4
+ require_relative '../lib/asian_character'
5
+
data/spec/word_spec.rb ADDED
@@ -0,0 +1,43 @@
1
+ # encoding: utf-8
2
+ require_relative 'spec_helper'
3
+
4
+ describe AsianCharacter::Word do
5
+
6
+ let(:word) {AsianCharacter::Word.new('二')}
7
+
8
+ it 'initializes' do
9
+ expect(word.class).to eq AsianCharacter::Word
10
+ end
11
+
12
+
13
+ describe "#pinyin" do
14
+
15
+ it 'returns pinyin' do
16
+ file = File.join(File.dirname(__FILE__), 'files', 'pinyin_er4.xml')
17
+ stub_request(:get, /GetWordPinyin\?/).
18
+ to_return(body: File.read(file))
19
+ expect(word.pinyin).to eq 'er4'
20
+ expect(word.cache).to be_false
21
+ expect(word.pinyin).to eq 'er4'
22
+ expect(word.cache).to be_true
23
+ end
24
+
25
+ end
26
+
27
+ describe "#sound_url" do
28
+
29
+ it 'returns sound url' do
30
+ file = File.join(File.dirname(__FILE__), 'files', 'sound_er4.xml')
31
+ stub_request(:get, /GetWordPinyinSoundMP3\?/).
32
+ to_return(body: File.read(file))
33
+ expect(word.sound_url).
34
+ to eq 'http://chinese.biodinfo.org/chinesefiles/soundci/4E8C.mp3'
35
+ expect(word.cache).to be_false
36
+ expect(word.sound_url).
37
+ to eq 'http://chinese.biodinfo.org/chinesefiles/soundci/4E8C.mp3'
38
+ expect(word.cache).to be_true
39
+ end
40
+
41
+ end
42
+
43
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: asian_character
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Jiangning Wang
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '10.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '10.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.14'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '2.14'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '1.13'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '1.13'
83
+ - !ruby/object:Gem::Dependency
84
+ name: debugger
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '1.6'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '1.6'
97
+ description: Provides some functions of Chinese
98
+ email:
99
+ - wangjn1982@163.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - asian_character.gemspec
110
+ - bundle_bin/autospec
111
+ - bundle_bin/htmldiff
112
+ - bundle_bin/ldiff
113
+ - bundle_bin/rake
114
+ - bundle_bin/rdebug
115
+ - bundle_bin/restclient
116
+ - bundle_bin/rspec
117
+ - examples/example.rb
118
+ - lib/asian_character.rb
119
+ - lib/asian_character/version.rb
120
+ - lib/asian_character/word.rb
121
+ - spec/asian_character_spec.rb
122
+ - spec/files/pinyin_er4.xml
123
+ - spec/files/sound_er4.xml
124
+ - spec/spec_helper.rb
125
+ - spec/word_spec.rb
126
+ homepage: ''
127
+ licenses:
128
+ - MIT
129
+ metadata: {}
130
+ post_install_message:
131
+ rdoc_options: []
132
+ require_paths:
133
+ - lib
134
+ required_ruby_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ! '>='
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ requirements: []
145
+ rubyforge_project:
146
+ rubygems_version: 2.0.7
147
+ signing_key:
148
+ specification_version: 4
149
+ summary: Provides some functions of Chinese
150
+ test_files:
151
+ - spec/asian_character_spec.rb
152
+ - spec/files/pinyin_er4.xml
153
+ - spec/files/sound_er4.xml
154
+ - spec/spec_helper.rb
155
+ - spec/word_spec.rb