[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

File resource location?

Jim Crossley

2/26/2005 4:30:00 PM

I have a Java application that I wish to port to Ruby. One of its
features is to convert a string of digits to a raw audio stream of
DTMF tones.

So the Java jar file includes raw audio files for each digit. These
are loaded as resources from the classpath.

What's the *right* way to do that in Ruby? Where do people typically
package resources for their applications?

Thanks,
Jim
2 Answers

Robert Klemme

2/26/2005 9:17:00 PM

0


"Jim Crossley" <jim@crossleys.org> schrieb im Newsbeitrag
news:87650fuvvy.fsf@vaio.crossleys.net...
>I have a Java application that I wish to port to Ruby. One of its
> features is to convert a string of digits to a raw audio stream of
> DTMF tones.
>
> So the Java jar file includes raw audio files for each digit. These
> are loaded as resources from the classpath.
>
> What's the *right* way to do that in Ruby? Where do people typically
> package resources for their applications?

Never had that problem, but one way would be to place them beside the module
..rb file or in a subdirectory and load them via the module file's name.

Regards

robert

Austin Ziegler

2/27/2005 3:48:00 AM

0

On Sun, 27 Feb 2005 06:20:00 +0900, Robert Klemme <bob.news@gmx.net> wrote:
> "Jim Crossley" <jim@crossleys.org > schrieb im Newsbeitrag
> news:87650fuvvy.fsf@vaio.crossleys.net...
>> I have a Java application that I wish to port to Ruby. One of its
>> features is to convert a string of digits to a raw audio stream
>> of DTMF tones.

>> So the Java jar file includes raw audio files for each digit.
>> These are loaded as resources from the classpath.

>> What's the *right* way to do that in Ruby? Where do people
>> typically package resources for their applications?
> Never had that problem, but one way would be to place them beside
> the module ..rb file or in a subdirectory and load them via the
> module file's name.

I've solved it a couple of ways. The first was to basically do:

% irb --noprompt
Dir["icons/*jpg"].each do |file|
File.open("#{file}.rb", "wb") do |wfile|
data = nil
File.open("#{file}", "rb") { |rfile| data = rfile.read }
wfile.write "#{file.tr('/.', '_').upcase} = #{data.inspect}"
end
end

The bad news, of course, is that this makes the file MUCH larger. If
you wanted, you could BASE64 encode the files and then decode them
on reading. However, the trick here is that you will get a valid
Ruby source file for your resource, and it can be found without any
additional work.

Alternatively, you can do what I'm doing in PDF::Writer, which is to
look for resource files in a predictable location, or in a specified
location. I do this with .afm files and now the appropriate .ttf
files.

-austin
--
Austin Ziegler * halostatue@gmail.com
* Alternate: austin@halostatue.ca