Permalink
Browse files

added normalizer for double Ns

  • Loading branch information...
1 parent 51119e7 commit d077da69c8803d0bdb872f5279def3c4f3f9dc19 @joeellis committed Jul 22, 2011
Showing with 22 additions and 0 deletions.
  1. +18 −0 lib/romajinizer.rb
  2. +4 −0 spec/romajinizer_spec.rb
View
@@ -14,6 +14,14 @@
# Repaired script to work with modern Ruby versions (1.86+), added comments,
# made it support gaijin friendly transliterations!
# ---------------------------------------------------------------------------------
+
+# ---------------------------------------------------------------------------------
+# Joe Ellis (joe at squarefour.net 2011-03-09)
+# Added a few more edge cases ('n romaji support),
+# Started gemifications so it can easily be used in any project
+# Added normalization for double nn so that こんばn will still be converted to こんばん properly
+# ---------------------------------------------------------------------------------
+
# USAGE
#
# Include kana2rom
@@ -278,13 +286,23 @@ def rom2kata
def kata2hira(str)
s=""; str.each_char{|c| s+=( Kata2hiraH.key?(c) ? Kata2hiraH[c] : c )}
+ s.normalize_double_n!
return s
end
def hira2kata(str)
s=""; str.each_char{|c|if(Hira2kataH.key?(c))then s+=Hira2kataH[c];else s+=c; end}
return s
end
+
+ def normalize_double_n
+ self.gsub(/n\'(?=[^aiueoyn]|$)/, "n")
+ end
+
+ def normalize_double_n!
+ self.gsub!(/n\'(?=[^aiueoyn]|$)/, "n")
+ self
+ end
# Added by Paul 2009-05-12 22:31
def kana2kana(str1)
@@ -21,4 +21,8 @@
"こんや".to_romaji.should == "konya"
"こんにち".to_romaji.should == "konnichi"
end
+
+ it "should convert kana to kana" do
+ "こんばn".to_hiragana.should == "こんばん"
+ end
end

0 comments on commit d077da6

Please sign in to comment.