Skip to content
Browse files

added helper methods for character to tell if it's a kanji character …

…or not
  • Loading branch information...
1 parent 2ea8bae commit 6bba526410374761ea237863bd87910a4759928b @joeellis committed Aug 2, 2011
Showing with 24 additions and 2 deletions.
  1. +16 −2 lib/romajinizer.rb
  2. +8 −0 spec/romajinizer_spec.rb
View
18 lib/romajinizer.rb
@@ -340,7 +340,21 @@ def kana2kana(str1)
def rom2hira
return kata2hira(rom2kata)
end
-
+
+ def is_kana?
+ if HiraganaCharacters.include?(self) == TRUE || KatakanaCharacters.include?(self) == TRUE
+ return true
+ end
+ return false
+ end
+
+ def is_kanji?
+ if HiraganaCharacters.include?(self) == FALSE && KatakanaCharacters.include?(self) == FALSE
+ return true
+ end
+ return false
+ end
+
def is_only_kana?
self.each_char do |character|
if HiraganaCharacters.include?(character) == FALSE && KatakanaCharacters.include?(character) == FALSE
@@ -349,7 +363,7 @@ def is_only_kana?
end
return true
end
-
+
def contains_kana?
self.each_char do |character|
if HiraganaCharacters.include?(character) == TRUE || KatakanaCharacters.include?(character) == TRUE
View
8 spec/romajinizer_spec.rb
@@ -35,4 +35,12 @@
"行きます".contains_kana?.should == true
"abcdefg".contains_kana?.should == false
end
+
+ it "should be able to tell if a character is a kana character" do
+ "".is_kana?.should == true
+ end
+
+ it "should be able to tell if a character is a kanji character" do
+ "".is_kanji?.should == true
+ end
end

0 comments on commit 6bba526

Please sign in to comment.
Something went wrong with that request. Please try again.