11155
(-- --)
1
Hi
Does anyone know of a quick way to convert human (string) numbers to
integers?
I doesnt need to be too fancy - the simple integers up to ten ( 10
will do.
Id prefer not to install a plugin or gem - so the solution is not native
to rails the possibly a '.collect' type algorithm?
Thanks for reading this!
Pieter
Hi
Does anyone know of a quick way to convert human (string) numbers to
integers?
I doesnt need to be too fancy - the simple integers up to ten ( 10 
will do.
Id prefer not to install a plugin or gem - so the solution is not native
to rails the possibly a ‘.collect’ type algorithm?
hmm… i don’t know of any but i’d create a method that goes like
def num_word_to_int(string
[‘zero’,‘one’,‘two’,‘three’,‘four’,‘five’,‘six’,‘seven’,‘eight’,‘nine’,‘ten’].rindex string
end
11155
(-- --)
3
Hi Jim - thanks - I came up with something similar - but using .index.
Cant seem to figure out the different?
Yours is more elegant with the leading 'zero' though. Thanks!
Pieter
Hi Jim - thanks - I came up with something similar - but using .index.
Cant seem to figure out the different?
Yours is more elegant with the leading ‘zero’ though. Thanks!
Thanks. glad to be of help 
What's wrong with Hash ?
{ "one" => 1
"two" => 2
...
}
You can generate such hash easily and make it a constant.
WordToInteger["one"] => 1
Robert Pankowecki