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
hostep
2
On Wed, Apr 13, 2011 at 6:08 PM, Pieter H. [email protected]
wrote:
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
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
–
hostep
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
hostep
4
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
hostep
5
On Wed, Apr 13, 2011 at 6:40 PM, Pieter H. [email protected]
wrote:
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
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
–