PLURALIZATION_EXCEPTIONS = "hardware",'memory'
def pluralize_category_name(name)
category = name.split(' and ')
exceptions_to_exp = ""
category.map! { |e|
if e.match(/^[A-Z]+$/) and !e.match(/^[A-Z]+S$/)
e = e.pluralize
end
(PLURALIZATION_EXCEPTIONS.include?(e.downcase) || e.match(/^[A-Z]+S$/) ||
e.match(/[memory|hardware]/) )? e : e.pluralize
}.join(' and ')
end
The test should and expectation should be as follows:
it "properly pluralizes hardware as hardware" do
pluralize_category_name("hardware").should == "hardware"
end
it "properly pluralizes UPS as UPS" do
pluralize_category_name("UPS").should == "UPS"
end
it "properly pluralizes PDA and Portable Hardware as PDAs and Portable Hardware" do
pluralize_category_name("PDA and Portable Hardware").should == "PDAs and Portable Hardware"
end
it "properly pluralizes perfume and cologne as perfumes and colognes" do
pluralize_category_name("perfume and cologne").should == "perfumes and colognes"
end
The last test fails :(
HELP!