lib/gimchi/korean.rb in gimchi-0.1.5 vs lib/gimchi/korean.rb in gimchi-0.1.6
- old
+ new
@@ -70,12 +70,12 @@
# @param [String, Number] str Numeric type or String containing numeric expressions
# @return [String] Output string
def read_number str
nconfig = config['number']
- str.to_s.gsub(/([+-]\s*)?[0-9,]*,*[0-9]+(\.[0-9]+(e[+-][0-9]+)?)?(\s*.)?/) {
- read_number_sub($&, $4)
+ str.to_s.gsub(/(([+-]\s*)?[0-9,]*,*[0-9]+(\.[0-9]+(e[+-][0-9]+)?)?)(\s*.)?/) {
+ read_number_sub($1, $5)
}
end
# Returns the pronunciation of the given string containing Korean characters.
# Takes optional options hash.
@@ -166,21 +166,21 @@
romanization = romanize_chunk.call k_chunk unless k_chunk.empty?
romanization
end
private
- def read_number_sub num, next_char = nil
+ def read_number_sub num, next_char
nconfig = config['number']
num = num.gsub(',', '')
- num = num.sub(/#{next_char}$/, '') if next_char
+ next_char = next_char.to_s
is_float = num.match(/[\.e]/) != nil
# Alternative notation for integers with proper suffix
alt = false
if is_float == false &&
- nconfig['alt notation']['when suffix'].keys.include?(next_char.to_s.strip)
+ nconfig['alt notation']['when suffix'].keys.include?(next_char.strip)
max = nconfig['alt notation']['when suffix'][next_char.strip]['max']
if max.nil? || num.to_i <= max
alt = true
end
@@ -263,25 +263,20 @@
str += tenfolds[(v / 10) - 1] if v / 10 > 0
v %= 10
str += digits[v] if v > 0
- if alt
- suffix = next_char.strip
- str = str + suffix
- alt_post_subs.each do | k, v |
- str.gsub!(k, v)
- end
- str.sub!(/#{suffix}$/, '')
- end
+ alt_post_subs.each do | k, v |
+ str.gsub!(k, v)
+ end if alt
tokens << str.sub(/ $/, '') + nconfig['units'][unit_idx]
end
end
num /= 10000
end
tokens += sign unless sign.empty?
- ret = tokens.reverse.join(' ') + below + next_char.to_s
+ ret = tokens.reverse.join(' ') + below + next_char
nconfig['post substitution'].each do | k, v |
ret.gsub!(k, v)
end
ret
end