On 16 June 2010 18:07, Michael Pavling <pavl...@gmail.com> wrote:

> On 16 June 2010 16:45, Ants Pants <antsmailingl...@gmail.com> wrote:
> > As I have said before, I have no problems with all of that but thanks for
> > the suggestions.
>
> To be honest, I don't really understand what you're asking for help
> with. If you can state your position in different terms, because what
> you've said so far obviously hasn't clicked with anyone (or at least
> we've clicked the same, wrong, way! ;-)
>
> Feeling around in the dark a little:
> http://snippets.dzone.com/posts/show/1137
> http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/170729
>
> The code you posted does look a little smelly. I don't know why you're
> turning your numbers into strings and then back into numbers again.
> For instance, where you say " ## need validation (can't have hundtedth
> without tenth, for example)", I think you could ignore if you just
> approach adding up the seconds differently.
>
> So for instance if :
>   time_units = {:seconds => 22, :hundredths => 0, :milliseconds => 8}
>
> you can just do the arithmetic:
>
>  fraction = 0
>  fraction += time_units[:tenths] * .1 if time_units.has_key?(:tenths)
>  fraction += time_units[:hundredths] * .01 if
> time_units.has_key?(:hundredths)
>  fraction += time_units[:milliseconds] *.001 if
> time_units.has_key?(:milliseconds)
>
> should result in 0.008
>
> Frankly, stuff the fraction variable. Treat @decimal_time the same:
>  @decimal_time += time_units[:seconds] if time_units.has_key?(:seconds)
>  @decimal_time += time_units[:minutes] * 60 if
> time_units.has_key?(:minutes)
>  @decimal_time += time_units[:hours] * 3600 if time_units.has_key?(:hours)
>  @decimal_time += time_units[:milliseconds] *.001 if
> time_units.has_key?(:milliseconds)
>  etc...
>
>
> Of course, ignore me if there's some critical reason they *must* be
> strings! :-)
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonrails-t...@googlegroups.com.
> To unsubscribe from this group, send email to
> rubyonrails-talk+unsubscr...@googlegroups.com<rubyonrails-talk%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>
Not to worry about this as I'm happy where I'm going. Logically it's not a
huge problem, getting it Rubyish might be ;) Long time Perl programmer.

Thanks for the links, I'd already seen the second link.

Thanks for the bit about the fractions, it's given me something to think
about but from what I can see, they will still have to be tacked on to the
decimal. The decimals were done the way you suggested but now they're just
in a loop (more flexible) as time_units may well be added in the future.

I don't want to labour on this so I'll just do what I was going to do.
Again, thanks.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to