I got curious about Active Record playing tricks with pluralization, and
found a few places in my rig where it might be useful. If you want to play
with it yourself, gem install localization, and you''ll get it.
There''s some
other cool stuff in there too!
Anyhow, I''m a bit stuck, or braindead. (actually both tonight) and
could use
some fresh ideas.
What I want to do is test a string to see if it is a plural, and if so
branch the code and do something else with it. Localization has a method to
convert from singular to plural, and back again, but as far as I can tell,
no way just to test plurality. Can you think of a way to do this test?
Here are some tests that should make my meaning clear.
require File.dirname(__FILE__) + ''/../test_helper''
require ''linguistics''
Linguistics::use( :en)
class LinguisticsTest < Test::Unit::TestCase
def test_conversion
assert_equal("mice","mouse".en.plural)
end
def test_converting_plural_word
assert_equal("mice","mice".en.plural, "mice not
recognized as plural")
end
def test_converting_plural_word_2
assert_equal("cats", "cats".en.plural, "cats not
recognized as plural")
end
#if there were a truth function, this would be it
def test_plural_truth
assert "cats".en.plural?
end
end
============== RESULTS =================
Loaded suite linguistics_test
Started
.FFE
Finished in 0.112234 seconds.
1) Failure:
test_converting_plural_word(LinguisticsTest) [linguistics_test.rb:12]:
mice not recognized as plural.
<"mice"> expected but was
<"mices">.
2) Failure:
test_converting_plural_word_2(LinguisticsTest) [linguistics_test.rb:16]:
cats not recognized as plural.
<"cats"> expected but was
<"cat">.
3) Error:
test_plural_truth(LinguisticsTest):
NoMethodError: undefined method `plural?'' for <English languageProxy
for
String object "cats">:#<Class:0xb7627b44>
/usr/lib/ruby/gems/1.8/gems/Linguistics-1.0.3/lib/linguistics.rb:90:in
`method_missing''
linguistics_test.rb:21:in `test_plural_truth''
4 tests, 3 assertions, 2 failures, 1 errors
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails