On Wednesday, August 23, 2006, at 12:35 PM, Trans wrote:
>
>Kevin Olbrich wrote:
>> On Wednesday, August 23, 2006, at 2:35 AM, Phrogz wrote:
>> >Kevin Olbrich wrote:
>> >> Announcing......
>> >>
>> >> Ruby Units
>> >
>> >Not to take the wind from your sails (fly, baby, fly!), but:
>> >http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/12821
>> >http://narray.rubyforge.org/quanty/quanty-en.html
>> >and my own foray:
>> >http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/154577
>> >
>> >
>>
>> The concept isn't new, but I think this approach has the fewest
>> limitations and is the most general.
>>
>> Besides, it was a good learning experince.
>
>Nice work. Though, you may be interested in Facets' units.rb, written
>by Peter Vanbroekhoven. It is about as complete as I can imagine it can
>get.
>
>  http://facets.rubyforge.org
>
>I think the currency conversion functionality is "off line" though. I
>need to fix that. It wuld be great if you took a look, maybe you would
>like to join the Facets team and work in innovations of your system. I
>have for sometime been thinking of releasing parts of Facets in
>"bite-sized" portions, staring in fact with units.rb, but I have bigger
>plans for distribution, so I've put it off.
>
>T.
>
>

Hey, amazing all the interesting stuff that pops up when you know where  
to look for it.

After a 15 minute look, I can see some issues with the current version  
of Units in facets.

1. It doesn't implement Comparable.
   1.cm < 2.m  #=> throws an exception in Facets
   "1 cm".unit < "2 m".unit  #=> returns true in ruby-units

2. The binary prefixes are incorrect (at least in the RDoc).  They  
should be like 'kibi = 2**10' and 'mebi = 2**20'.

3. Facet Units doesn't seem to do temperature conversions.  Maybe it  
does, but I can't find any documentation on it.

4. I haven't found a simple way to convert a string into a Unit using  
Facets.  One reason that ruby-units does this is because I wanted to  
make it easy for users to provide units as input and then parse them.   
The facets Units seem to work fine if you know which units you want to  
use when you write your program.

5. ruby-units is much more flexible in terms of what units it recognizes  
with the default configuration.
  1.attoparsec/microfortnight.to(inch/s)  # => fails in Facets
  "1 attoparsec/microfortnight".unit("in/s") #=> "1.0043269330917 in/s"  
in ruby-units

6. Facets seems to get in trouble when the name of a unit collides with  
a ruby keyword
  1.m.to(in) #=> causes a parse error in Facets
  This isn't an issue in ruby-units since all the units are specified as  
strings.

7. ruby-units does not do dynamic currency conversions right now.

8. Facet Units does not seem to implement may Numeric methods like (abs,  
ceil, floor, to_i, round, etc..).  This works as you would expect with  
ruby-units.

9. Facet Units seems to be unable to simplify units in some cases..
   (1.m * 1.m) / (1.cm * 1.cm) #=> 1 m**2/cm**2
   I can't figure out how to convert this result to a float.

   In ruby-units, the equivalent would be.
   ("1 m".unit * "1 m".unit / ("1 cm".unit * "1 cm".unit)).to_base.to_f  
#=> 10000.0

Disclaimer:  Some of these observations may be erroneous due to my  
unfamiliarity with this package.  Feel free to correct them.

I'd be happy to work with Facets to improve it's handling of units.

_Kevin
www.sciwerks.com

-- 
Posted with http://DevLists.com.  Sign up and save your mailbox.