Facets Units. How do I use it?

F

fREW Schmidt

Hi all,

I am trying to use the facet units and I am having no luck. If I do

require 'facets'

and I still can't use any for the unit examples on the facets site. So
I tried to do

require 'facet/units'

and I get the following error

ArgumentError: wrong number of arguments (0 for 1)
from
/usr/lib/ruby/gems/1.8/gems/facets-1.8.54/lib/facets/more/units.rb:710:in
`b'
from
/usr/lib/ruby/gems/1.8/gems/facets-1.8.54/lib/facets/more/units.rb:710:in
`clean_eval'
from
/usr/lib/ruby/gems/1.8/gems/facets-1.8.54/lib/facets/more/units.rb:710:in
`clean_eval'
from
/usr/lib/ruby/gems/1.8/gems/facets-1.8.54/lib/facets/more/units.rb:753:in
`decode_conversion'
from
/usr/lib/ruby/gems/1.8/gems/facets-1.8.54/lib/facets/more/units.rb:572:in
`register_unit'
from
/usr/lib/ruby/gems/1.8/gems/facets-1.8.54/lib/facets/more/units.rb:720:in
`register_prefixed_unit'
from
/usr/lib/ruby/gems/1.8/gems/facets-1.8.54/lib/facets/more/units.rb:598:in
`register_binary_unit'
from
/usr/lib/ruby/gems/1.8/gems/facets-1.8.54/lib/facets/more/units.rb:654:in
`load_yaml'
from
/usr/lib/ruby/gems/1.8/gems/facets-1.8.54/lib/facets/more/units.rb:639:in
`each'
from
/usr/lib/ruby/gems/1.8/gems/facets-1.8.54/lib/facets/more/units.rb:639:in
`load_yaml'
from
/usr/lib/ruby/gems/1.8/gems/facets-1.8.54/lib/facets/more/units.rb:646:in
`load_yaml'
from
/usr/lib/ruby/gems/1.8/gems/facets-1.8.54/lib/facets/more/units.rb:639:in
`each'
from
/usr/lib/ruby/gems/1.8/gems/facets-1.8.54/lib/facets/more/units.rb:639:in
`load_yaml'
from
/usr/lib/ruby/gems/1.8/gems/facets-1.8.54/lib/facets/more/units.rb:521:in
`from_yaml'
from
/usr/lib/ruby/gems/1.8/gems/facets-1.8.54/lib/facets/more/units.rb:530:in
`instance_eval'
from
/usr/lib/ruby/gems/1.8/gems/facets-1.8.54/lib/facets/more/units.rb:530:in
`initialize'
from
/usr/lib/ruby/gems/1.8/gems/facets-1.8.54/lib/facets/more/units.rb:520:in
`new'
from
/usr/lib/ruby/gems/1.8/gems/facets-1.8.54/lib/facets/more/units.rb:520:in
`from_yaml'
from
/usr/lib/ruby/gems/1.8/gems/facets-1.8.54/lib/facets/more/units.rb:812
from
/usr/lib/ruby/gems/1.8/gems/facets-1.8.54/lib/facets/more/units.rb:811:in
`each'
from
/usr/lib/ruby/gems/1.8/gems/facets-1.8.54/lib/facets/more/units.rb:811
from
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in
`gem_original_require'
from
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
from
/usr/lib/ruby/gems/1.8/gems/facets-1.8.54/lib/facet/units.rb:1
from
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:32:in
`gem_original_require'
from
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:32:in `require'


Any ideas on what I am doing wrong?
 
C

Calamitas

Hi all,

I am trying to use the facet units and I am having no luck. If I do

require 'facets'

and I still can't use any for the unit examples on the facets site. So
I tried to do

require 'facet/units'

and I get the following error
[snip]

Any ideas on what I am doing wrong?

Thanks for the bug report. This is the easiest way to reproduce your error:
ArgumentError: wrong number of arguments (0 for 1)
from /home/peterv/local/lib/ruby/gems/1.8/gems/facets-1.8.54/lib/facets/more/units.rb:710:in
`b'
from /home/peterv/local/lib/ruby/gems/1.8/gems/facets-1.8.54/lib/facets/more/units.rb:710:in
`clean_eval'
from /home/peterv/local/lib/ruby/gems/1.8/gems/facets-1.8.54/lib/facets/more/units.rb:710:in
`clean_eval'

Basically, you have a definition of b in Kernel or Object that
interferes with Facets Units. A quick fix would be to undef b:
=> true

Or you could try to figure out how b got defined, which is probably a
library if you didn't define it yourself, and just not load that
library if you want to use Units for the moment.

Peter
 
F

Frew Schmidt

Ah! Brilliant. I had forgotten about that. In my irbrc I defined a
couple methods to help me with some homework (converting to and from
binary) and one was called b.

If I wanted to load up units sans the web-based conversion rates is
there a way that I could do that without modifying the actual source of
units.rb? I am thinking about using this for an app that I would want
to have really really fast response time but I would want to do some
date math and this looks like it could be helpful for that.
 
C

Calamitas

Ah! Brilliant. I had forgotten about that. In my irbrc I defined a
couple methods to help me with some homework (converting to and from
binary) and one was called b.

If I wanted to load up units sans the web-based conversion rates is
there a way that I could do that without modifying the actual source of
units.rb? I am thinking about using this for an app that I would want
to have really really fast response time but I would want to do some
date math and this looks like it could be helpful for that.

The exchange rates are not actually the reason for the slow start-up
(the exchanged rates are looked up lazily). Tackling the slow start-up
time is planned for the next version of Units, but at the moment I
still don't have enough time (I may find some in a month or so).

As for date calculations, currently Units only has a notion of
duration, and it seems only up to days. The current version doesn't
define interaction with actual dates, like adding a month to a today's
date and such. You might want to look at Active Support for the
moment.

Peter
 
F

Frew Schmidt

The exchange rates are not actually the reason for the slow start-up
(the exchanged rates are looked up lazily). Tackling the slow start-up
time is planned for the next version of Units, but at the moment I
still don't have enough time (I may find some in a month or so).

As for date calculations, currently Units only has a notion of
duration, and it seems only up to days. The current version doesn't
define interaction with actual dates, like adding a month to a today's
date and such. You might want to look at Active Support for the
moment.

Peter

Thanks for the tips! I'll look into it for sure. I think that the
stuff I am doing is simple enough that I can do it by hand (you know,
minute = 60, hour = 60 * minute, use jurian dates, etc.) I don't know
if something in my setup is broken or something, but the vast majority
of the examples in the Doc didn't work at all. Here's what happened:
NameError: undefined local variable or method `s' for main:Object
from (irb):2NameError: undefined local variable or method `s' for main:Object
from (irb):3NameError: undefined local variable or method `feet' for main:Object
from (irb):4NameError: undefined local variable or method `yd' for main:Object
from (irb):5NameError: undefined local variable or method `sq_yd' for main:Object
from (irb):6NoMethodError: undefined method `L' for main:Object
from (irb):7NameError: undefined local variable or method `kg' for main:Object
from (irb):8NameError: undefined local variable or method `m' for main:Object
from (irb):9NameError: undefined local variable or method `km' for main:Object
from (irb):10NameError: undefined local variable or method `km' for main:Object
from (irb):11NameError: undefined local variable or method `twd' for main:Object
from (irb):12



If I did like, 1.bit + 1.byte it would work, but the examples above all
failed apparently.
 
C

Calamitas

Thanks for the tips! I'll look into it for sure. I think that the
stuff I am doing is simple enough that I can do it by hand (you know,
minute = 60, hour = 60 * minute, use jurian dates, etc.) I don't know
if something in my setup is broken or something, but the vast majority
of the examples in the Doc didn't work at all. Here's what happened:

NameError: undefined local variable or method `s' for main:Object
from (irb):2
NameError: undefined local variable or method `s' for main:Object
from (irb):3
NameError: undefined local variable or method `feet' for main:Object
from (irb):4
NameError: undefined local variable or method `yd' for main:Object
from (irb):5
NameError: undefined local variable or method `sq_yd' for main:Object
from (irb):6
NoMethodError: undefined method `L' for main:Object
from (irb):7
NameError: undefined local variable or method `kg' for main:Object
from (irb):8
NameError: undefined local variable or method `m' for main:Object
from (irb):9
NameError: undefined local variable or method `km' for main:Object
from (irb):10
NameError: undefined local variable or method `km' for main:Object
from (irb):11
NameError: undefined local variable or method `twd' for main:Object
from (irb):12



If I did like, 1.bit + 1.byte it would work, but the examples above all
failed apparently.

You need to include the Units module first (this is to prevent
unwanted name space pollution):
=> 65.0 bit/s

Note that the current version of Units contains a few embarrassing
bugs that should be removed in the next release (but when that is, is
not up to me). Also, last time I checked, the web service I used for
the currency conversion has ceased working.

Peter
 
T

Trans

Hi--

A new version of Units will be out in a week or two as part of Facets
2.0. This is a big release and I have a nunber of things to finish up
first. If you'd like an early-bird release, let me know. I can send
you a copy of the current repository.

The currency exhange rates is still in limbo though. I think we might
move these to a secondary lib (eg. require 'facets/units/currency')
and work on them after the next release.

Also, for date/time methods you might want to try

require 'facets/more/times'

Which is very much like the Active Support lib, both of which are
based on the original work of Rich Kilmer.

T.
 
F

Frew Schmidt

Also, for date/time methods you might want to try
require 'facets/more/times'

Which is very much like the Active Support lib, both of which are
based on the original work of Rich Kilmer.

T.

Thanks much, I will definitely check that out.

I don't know if this is of use to you, but some people over here were
just doing some cooking stuff and trying to convert tablespoons to
ounces, and cc's to tablespoons and whatnot. I know that Units is not
supposed to be that kind of deal, but it might be worth it to add in
those things.

Thanks again for all of your help!
 
T

Trans

Thanks much, I will definitely check that out.

I don't know if this is of use to you, but some people over here were
just doing some cooking stuff and trying to convert tablespoons to
ounces, and cc's to tablespoons and whatnot. I know that Units is not
supposed to be that kind of deal, but it might be worth it to add in
those things.

Good idea. Will put it on the TODOs.

Thanks,
T.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Facets units not working 2
File upload help 3
facets 3
RubyCocoa: How do I fix this? 0
method `tlsconnect' not defined in Net::SMTP 1
Oracle-oci8.2.0 4
Plugin errors 0
Vimeo API Error, `gem_original_require 0

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,132
Latest member
TeresaWcq1
Top