gimchi 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/config/default.yml CHANGED
@@ -107,7 +107,8 @@ number:
107
107
  tenfolds: [열, 스물, 서른, 마흔, 쉰, 예순, 일흔, 여든, 아흔, 백]
108
108
  digits: ["", 한, 두, 세, 네, 다섯, 여섯, 일곱, 여덟, 아홉]
109
109
  post substitution:
110
- 물살: 무살
110
+ ? !ruby/regexp /스물$/
111
+ : 스무
111
112
 
112
113
  romanization:
113
114
  chosung:
data/lib/gimchi/korean.rb CHANGED
@@ -72,8 +72,8 @@ class Korean
72
72
  def read_number str
73
73
  nconfig = config['number']
74
74
 
75
- str.to_s.gsub(/([+-]\s*)?[0-9,]*,*[0-9]+(\.[0-9]+(e[+-][0-9]+)?)?(\s*.)?/) {
76
- read_number_sub($&, $4)
75
+ str.to_s.gsub(/(([+-]\s*)?[0-9,]*,*[0-9]+(\.[0-9]+(e[+-][0-9]+)?)?)(\s*.)?/) {
76
+ read_number_sub($1, $5)
77
77
  }
78
78
  end
79
79
 
@@ -168,17 +168,17 @@ class Korean
168
168
  end
169
169
 
170
170
  private
171
- def read_number_sub num, next_char = nil
171
+ def read_number_sub num, next_char
172
172
  nconfig = config['number']
173
173
 
174
174
  num = num.gsub(',', '')
175
- num = num.sub(/#{next_char}$/, '') if next_char
175
+ next_char = next_char.to_s
176
176
  is_float = num.match(/[\.e]/) != nil
177
177
 
178
178
  # Alternative notation for integers with proper suffix
179
179
  alt = false
180
180
  if is_float == false &&
181
- nconfig['alt notation']['when suffix'].keys.include?(next_char.to_s.strip)
181
+ nconfig['alt notation']['when suffix'].keys.include?(next_char.strip)
182
182
  max = nconfig['alt notation']['when suffix'][next_char.strip]['max']
183
183
 
184
184
  if max.nil? || num.to_i <= max
@@ -265,14 +265,9 @@ private
265
265
  v %= 10
266
266
  str += digits[v] if v > 0
267
267
 
268
- if alt
269
- suffix = next_char.strip
270
- str = str + suffix
271
- alt_post_subs.each do | k, v |
272
- str.gsub!(k, v)
273
- end
274
- str.sub!(/#{suffix}$/, '')
275
- end
268
+ alt_post_subs.each do | k, v |
269
+ str.gsub!(k, v)
270
+ end if alt
276
271
  tokens << str.sub(/ $/, '') + nconfig['units'][unit_idx]
277
272
  end
278
273
  end
@@ -280,7 +275,7 @@ private
280
275
  end
281
276
 
282
277
  tokens += sign unless sign.empty?
283
- ret = tokens.reverse.join(' ') + below + next_char.to_s
278
+ ret = tokens.reverse.join(' ') + below + next_char
284
279
  nconfig['post substitution'].each do | k, v |
285
280
  ret.gsub!(k, v)
286
281
  end
data/test/test_gimchi.rb CHANGED
@@ -91,7 +91,11 @@ class TestGimchi < Test::Unit::TestCase
91
91
  assert_equal "플러스 십점영", ko.read_number("+ 10.0")
92
92
 
93
93
  # 나이, 시간, 개수, 명 ( -살, -시, -개, -명 )
94
+ assert_equal "나는 이십", ko.read_number("나는 20")
94
95
  assert_equal "나는 스무살", ko.read_number("나는 20살")
96
+ assert_equal "나는 스물네살", ko.read_number("나는 24살")
97
+ assert_equal "스무개", ko.read_number("20개")
98
+ assert_equal "스무 명", ko.read_number("20 명")
95
99
  assert_equal "이십 칠점일살", ko.read_number("27.1살")
96
100
  assert_equal "너는 열세 살", ko.read_number("너는 13 살")
97
101
  assert_equal "백 서른두명", ko.read_number("132명")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gimchi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-04-12 00:00:00.000000000Z
12
+ date: 2011-04-13 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
- requirement: &2152493140 !ruby/object:Gem::Requirement
16
+ requirement: &2152254860 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.0.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2152493140
24
+ version_requirements: *2152254860
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: jeweler
27
- requirement: &2152491800 !ruby/object:Gem::Requirement
27
+ requirement: &2152253040 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.5.2
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2152491800
35
+ version_requirements: *2152253040
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rcov
38
- requirement: &2152490620 !ruby/object:Gem::Requirement
38
+ requirement: &2152251640 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2152490620
46
+ version_requirements: *2152251640
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: ansi
49
- requirement: &2152489680 !ruby/object:Gem::Requirement
49
+ requirement: &2152249420 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: 1.2.2
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2152489680
57
+ version_requirements: *2152249420
58
58
  description: Gimchi knows how to pronounce Korean strings and how to write them in
59
59
  roman alphabet.
60
60
  email: junegunn.c@gmail.com
@@ -93,7 +93,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
93
93
  version: '0'
94
94
  segments:
95
95
  - 0
96
- hash: -4096346844211308775
96
+ hash: 170191827344354628
97
97
  required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  none: false
99
99
  requirements: