Singularize error

0 views
Skip to first unread message

Joel

unread,
Nov 12, 2009, 7:23:05 PM11/12/09
to ActiveJS
Not so much an error but in the ActiveSupport.Inflector.singularize
function you do:

if (word.toLowerCase == uncountable)

and

if ((word.toLowerCase == singular) || (word == plural))

Shouldn't that be toLowerCase()? Ie it should be a function call?

Also in my app, I've cached the singularize calls (as it gets called
alot! - 7000 times!):

singularize: function singularize(word) {
var i;
var result = '';
var originalWord = word;
if (this.singularizeStore[word]) return this.singularizeStore
[word];
var word = word.toLowerCase();
for (i = 0; i <
ActiveSupport.Inflector.Inflections.uncountable.length; i++) {
var uncountable =
ActiveSupport.Inflector.Inflections.uncountable[i];
if (word === uncountable) {
result = originalWord;
break;
}
}
if (result == '') {
for (i = 0; i <
ActiveSupport.Inflector.Inflections.irregular.length; i++) {
var singular =
ActiveSupport.Inflector.Inflections.irregular[i][0];
var plural =
ActiveSupport.Inflector.Inflections.irregular[i][1];
if ((word === singular) || (word === plural)) {
result = originalWord;
break;
}
}
if (result == '') {
for (i = 0; i <
ActiveSupport.Inflector.Inflections.singular.length; i++) {
var regex =
ActiveSupport.Inflector.Inflections.singular[i][0];
var replace_string =
ActiveSupport.Inflector.Inflections.singular[i][1];
if (regex.test(originalWord)) {
result = originalWord.replace(regex, replace_string);
break;
}
}
}
}
this.singularizeStore[originalWord] = result;
if (result != '') {
return result;
}
}

nlloyds

unread,
Nov 14, 2009, 9:53:44 AM11/14/09
to ActiveJS
Joel,

Thanks for pointing this out. Could you please open a ticket on the
Lighthouse (https://aptana.lighthouseapp.com/projects/22012-activejs/
overview)?

Nathan

Ryan Johnson

unread,
Nov 16, 2009, 9:17:26 AM11/16/09
to acti...@googlegroups.com
Maybe this is an old build? I remember this issue and thought it had been fixed.
> --
>
> You received this message because you are subscribed to the Google Groups "ActiveJS" group.
> To post to this group, send email to acti...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/activejs?hl=.
>
>
>
>

Joel

unread,
Nov 16, 2009, 10:27:55 PM11/16/09
to ActiveJS
Just checked the latest code in github and it still has this problem.

Also I had a small mistake in my code this line:

if (this.singularizeStore[word]) return this.singularizeStore[word];

should be:

if (typeof this.singularizeStore[word] != 'undefined') return
this.singularizeStore[word];

On Nov 17, 1:17 am, Ryan Johnson <r...@syntacticx.com> wrote:
> Maybe this is an old build? I remember this issue and thought it had been fixed.
>
Reply all
Reply to author
Forward
0 new messages