chinese_pinyin 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6b19a3fd8b5753309a20ca9606e36fb1d2c3b1e65256006f45875ef7a2113ec7
4
- data.tar.gz: 1e6e4004e23954b6ce5be09cf348c2de60949fd8c17a6fbac20590fb29613f78
3
+ metadata.gz: 23e4d70b5131cb483c5a9a6a542b1310ad4cad4535e8d295ff58ba9338f2b930
4
+ data.tar.gz: 1224699549ee0d9d644e1f96d084a3c17c7754f9236d2a21311a152fafd73b52
5
5
  SHA512:
6
- metadata.gz: 446b0eacb9b4de236b7cc7d514ae6f962c1167e4a55e886bd4226f5248a4f2be2282068dd0134077068324285bc1fe5c4ac4dbd83c63cb94e224c47c70bf01c8
7
- data.tar.gz: 0c90d687de3815836e3d5f9f984eea53093b4a2cdde65a662bdf23e0988d4b4b4546023cc0f17e6e8db4ace3188cbf070da5269b44fc6270adcd7f26667db7ec
6
+ metadata.gz: 4d913acf6b8b162685957081afc5ccc6a47337e1a5481bb347a27ae8748c16f87f56c367c0a064fe1b09246d288c7680064bb1f4673dcebce669f64e3c9b458d
7
+ data.tar.gz: 5974408e11538bc96644ef3b8f7b41c9b5a381719bd495347217eb5165a8771dc34d7d94c810bb0543b66aaa6a79c2d64aa268845187dad167244836cf032950
@@ -0,0 +1,26 @@
1
+ name: Chinese Pinyin
2
+
3
+ on:
4
+ pull_request:
5
+ branches:
6
+ - 'master'
7
+
8
+ push:
9
+ branches:
10
+ - 'ruby3-support'
11
+ - 'master'
12
+
13
+ jobs:
14
+ build:
15
+ runs-on: ubuntu-latest
16
+ strategy:
17
+ matrix:
18
+ ruby: ['2.1', '2.5', '2.6', '2.7', '3.0']
19
+ steps:
20
+ - uses: actions/checkout@v1
21
+ - uses: ruby/setup-ruby@v1
22
+ with:
23
+ ruby-version: ${{ matrix.ruby }}
24
+ - name: Build and test with Rake
25
+ run: |
26
+ rake test
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Next Release
2
2
 
3
+ ## 1.1.0 (04/19/2021)
4
+
5
+ * support ruby 3
6
+
3
7
  ## 1.0.2 (08/19/2019)
4
8
 
5
9
  * add 嗯 to pinyin-utf8.dat
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # ChinesePinyin
2
2
 
3
- [![Build Status](https://secure.travis-ci.org/flyerhzm/chinese_pinyin.png)](http://travis-ci.org/flyerhzm/chinese_pinyin)
3
+ [![Chinese Pinyin](https://github.com/flyerhzm/chinese_pinyin/actions/workflows/chinese_pinyin.yml/badge.svg)](https://github.com/flyerhzm/chinese_pinyin/actions/workflows/chinese_pinyin.yml)
4
4
 
5
5
  Translate chinese hanzi to pinyin.
6
6
 
data/Rakefile CHANGED
@@ -1,8 +1,6 @@
1
1
  $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
2
- require "bundler"
3
- Bundler.setup
4
2
 
5
- require "rake"
3
+ require 'bundler/setup'
6
4
  require 'rake/testtask'
7
5
  require "rdoc/task"
8
6
 
@@ -16,17 +16,18 @@ class Pinyin
16
16
 
17
17
  class <<self
18
18
  attr_accessor :table
19
- attr_accessor :ruby2
19
+ attr_accessor :ruby1
20
20
 
21
21
  def init_table
22
22
  return if @table
23
23
 
24
24
  # Ruby 2.0以后默认即为UTF-8编码,使用新的码表以提升效率
25
- @ruby2 = !!(RUBY_VERSION =~ /^2/)
26
- datfile = @ruby2 ? 'pinyin-utf8.dat' : 'Mandarin.dat'
25
+ @ruby1 = !!(RUBY_VERSION =~ /^1/)
26
+ datfile = @ruby1 ? 'Mandarin.dat' : 'pinyin-utf8.dat'
27
27
  @table = {}
28
28
 
29
- File.open(File.dirname(__FILE__) + "/../data/#{datfile}", "r:UTF-8",) do |file|
29
+ file = File.join(File.dirname(__FILE__), "../data/#{datfile}")
30
+ File.open(file, "r:UTF-8",) do |file|
30
31
  while line = file.gets
31
32
  key, value = line.split(' ', 2)
32
33
  @table[key] = value
@@ -50,7 +51,7 @@ class Pinyin
50
51
  end
51
52
 
52
53
  def translate(chars, options={})
53
- chars = chars.force_encoding("UTF-8")
54
+ chars = chars.encode("UTF-8")
54
55
  splitter = options.fetch(:splitter, ' ')
55
56
  tonemarks = options.fetch(:tonemarks, false)
56
57
  tone = options.fetch(:tone, false || tonemarks)
@@ -72,7 +73,7 @@ class Pinyin
72
73
  is_english = false
73
74
 
74
75
  chars.scan(/./).each do |char|
75
- key = @ruby2 ? char : sprintf("%X", char.unpack("U").first)
76
+ key = @ruby1 ? sprintf("%X", char.unpack("U").first) : char
76
77
 
77
78
  if @table[key]
78
79
  results << splitter if is_english
@@ -80,7 +81,7 @@ class Pinyin
80
81
  is_english = false
81
82
  pinyin = @table[key].chomp.split(' ', 2)[0]
82
83
 
83
- pinyin.downcase! unless @ruby2
84
+ pinyin.downcase! if @ruby1
84
85
  pinyin.chop! unless tone
85
86
  pinyin.capitalize! if camel
86
87
  if tonemarks
@@ -1,4 +1,5 @@
1
1
  # encoding: utf-8
2
+
2
3
  module ChinesePinyin
3
- VERSION = "1.0.2"
4
+ VERSION = "1.1.0"
4
5
  end
@@ -1,4 +1,5 @@
1
1
  # -*- encoding : utf-8 -*-
2
+
2
3
  require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
3
4
 
4
5
  ENV["WORDS_FILE"] = File.dirname(__FILE__) + '/Words.dat'
@@ -10,6 +11,11 @@ class PinyinTest < Test::Unit::TestCase
10
11
  assert_equal("shang hai very good o ye", Pinyin.t('上海very good哦耶'))
11
12
  end
12
13
 
14
+ def test_t_with_frozen_string
15
+ assert_equal("zhong guo", Pinyin.t('中国'.freeze))
16
+ assert_equal("shen zhen", Pinyin.t('深圳'.freeze))
17
+ end
18
+
13
19
  def test_t_with_splitter
14
20
  assert_equal("zhong-guo", Pinyin.t('中国', splitter: '-'))
15
21
  assert_equal("huangzhimin", Pinyin.t('黄志敏', splitter: ''))
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chinese_pinyin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  - Hong, Liang
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-08-19 00:00:00.000000000 Z
12
+ date: 2021-04-18 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: translate chinese hanzi to pinyin.
15
15
  email:
@@ -20,8 +20,8 @@ executables:
20
20
  extensions: []
21
21
  extra_rdoc_files: []
22
22
  files:
23
+ - ".github/workflows/chinese_pinyin.yml"
23
24
  - ".gitignore"
24
- - ".travis.yml"
25
25
  - CHANGELOG.md
26
26
  - Gemfile
27
27
  - MIT-LICENSE
@@ -40,7 +40,7 @@ homepage: http://github.com/flyerhzm/chinese_pinyin
40
40
  licenses:
41
41
  - MIT
42
42
  metadata: {}
43
- post_install_message:
43
+ post_install_message:
44
44
  rdoc_options: []
45
45
  require_paths:
46
46
  - lib
@@ -55,8 +55,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
55
  - !ruby/object:Gem::Version
56
56
  version: 1.3.6
57
57
  requirements: []
58
- rubygems_version: 3.0.3
59
- signing_key:
58
+ rubygems_version: 3.1.4
59
+ signing_key:
60
60
  specification_version: 4
61
61
  summary: translate chinese hanzi to pinyin.
62
62
  test_files:
data/.travis.yml DELETED
@@ -1,3 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.3.0