hanzi 0.2.0 → 0.2.1

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.rdoc CHANGED
@@ -11,6 +11,9 @@ Example usage:
11
11
  Hanzi.to_pinyin('no! 为什么!') # no! wei4shen2me5!
12
12
  Hanzi.to_pinyin('你好, 我是康昱辰。') # ni3hao3, wo3shi4kang1yu4chen2。
13
13
 
14
+ Hanzi.to_english('孔子') # Confucius (551-479 BC), Chinese thinker and social philosopher, also known as 孔夫子[Kong3 fu1 zi3]
15
+ Hanzi.to_english('老子喜欢') # nil (can only translate exact word matches)
16
+
14
17
  To run tests:
15
18
 
16
19
  rake test
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
data/hanzi.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "hanzi"
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Steve Jackson"]
data/lib/hanzi.rb CHANGED
@@ -52,7 +52,7 @@ class Hanzi
52
52
  match = nil
53
53
  match_length = 0
54
54
  4.downto(1) do |length|
55
- match = find_match(text[pos, length])
55
+ match = find_hanzi_match(text[pos, length])
56
56
  match_length = length
57
57
  break if match
58
58
  end
@@ -70,8 +70,15 @@ class Hanzi
70
70
  result
71
71
  end
72
72
 
73
+ def to_english(text)
74
+ load_data if @data.nil?
75
+
76
+ entry = find_hanzi_match(text)
77
+ entry[:english] if entry && entry[:english]
78
+ end
79
+
73
80
  private
74
- def find_match(text)
81
+ def find_hanzi_match(text)
75
82
  entry = @data.find do |word|
76
83
  word[:simplified] == text || word[:traditional] == text
77
84
  end
data/test/test_hanzi.rb CHANGED
@@ -34,4 +34,14 @@ class TestHanzi < Test::Unit::TestCase
34
34
  assert_equal 'ni3hao3, wo3shi4kang1yu4chen2。', result
35
35
  end
36
36
 
37
+ def test_can_return_english_translation
38
+ result = Hanzi.to_english('你好')
39
+ assert result.downcase.include?('hello')
40
+ end
41
+
42
+ def test_returns_nil_for_not_found_english_translation
43
+ result = Hanzi.to_english('老子你好')
44
+ assert_equal result, nil
45
+ end
46
+
37
47
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hanzi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -78,7 +78,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
78
78
  version: '0'
79
79
  segments:
80
80
  - 0
81
- hash: 2598915566647370745
81
+ hash: -991267641606687232
82
82
  required_rubygems_version: !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements: