i'm looking for gem(s) which will provide me tools for File and Directory manipulation.
Basicly i would like to get possibility to:
search file in provided directory
search pattern inside file (different extensions)
insert into file at precise place content
I know how to do it using Ruby, but it would be nice to get such gem :)
Thanks
Anwser is NO, there isn't one.
Related
I would like to place the .irbrc file in my project folder to configure the irb console just for that specific project. I am aware that i can configure .irbrc placing it in the home folder but i would like to avoid that, i just want to require all the files of my project when i get into the console, but i am not looking for a permanent behaviour
I am trying to place .irbrc file in the project root but it does not seem to be requiring anything if i place it there.
Is it possible to do it??.
Any suggestion would be much appreciated.
Thank you so much
Does your project have a ./bin/console file? Probably that's what you're looking for.
Here is some information about it: Your Ruby App Should Have a bin/console.
However, you can pass another file to be loaded in irb:
IRBRC="~/Documents/.irbrc" irb
You can look at how irb loads it in init.rb, if you're interested.
I have done several small scripting/automation projects before but this is my first time using MacRuby and I couldn't find out at all why my project is not working.
This task would have been easy to fix if it was just a plain Ruby script. However, it needs a Mac GUI so I decided to use MacRuby for its Cocoa bindings.
The app itself is a simple form that will perform a calculation based from some data from an external CSV and some text fields and then show the results of the calculation.
My problem is that this code does NOT seem to work:
#arr_from_csv = CSV.read("data.csv")
Upon building the file, I get the following error:
[...]/ruby/1.9.2/CSV.rb:1335:in `open': No such file or directory - open() failed (Errno::ENOENT)
At first, I thought that I must have put the CSV file into the wrong directory inside XCode project's folder structure. I tried putting on the same folder as the script itself (app_delegate.rb). Didn't work. I tried putting it in the Resources folder, still didn't work.
Then, I decided to just use an absolute file path. So, I changed to code into:
#arr_from_csv = CSV.read("~/data.csv")
and copied the file into my home directory. It still can't read the CSV file.
Am I missing something? I'm sorry, this is my first time using MacRuby.
Thanks.
You should change the code to "/Users/xxx/data.csv".
Ruby does not expand "~" to "/Users/xxx".
Notice: xxx represents your login id.
I was able to solve my problem by using:
#arr_from_csv = CSV.read(File.expand_path("~/data.csv"))
I have a dozen of selenium webdriver scripts written in Ruby and I have used both rubyscript2exe and ocra gems in an attempt to end up with a 'bundled' executable but to no avail. Problem is, my scripts are grabbing test data from Excel files; and this is causing havoc when trying to create the executable.
It works fine on the machine which has the original excel file but when taken home away from its native path it 'll just refuse to run. Do I need to declare my paths in my code in a relative way and not explicitly? Is there a command in Ruby like 'require' but for an Excel file for example?
I will be grateful if anyone knows a way to make a ruby executable (or even an installer/application builder) which will somehow include the Excel files running in parallel with the script.
* Resolved *
Admins you can close this one if you want.
It was pretty simple but couldn't figure it out on the first place. If you want to included additional non ruby files in your final executable you can use the line below..:
ocra yourscript.rb test.xls docs\documentantion.doc excel\additional.xls
Once you package an exe using Ocra the files are locked inside it, and if they're intended to be immutable you may as well store the data in the script and write it out directly from there. If you absolutely can't do it without an excel file you'd might also consider creating one via the script.
If you're using an external excel file which is distributed with the exe, then you'd be best off referencing the excel file's path relative to the script (Dir.pwd). Also, wouldn't it be more efficient to gather the data from a delimited text file rather than excel?
I'm working on a project that needs to get a file list from a variety of different archives files (tar.gz, rar, tar.bz2, and zip) without expanding the archive. Rubyzip works well for zip files, but I can't find any equivalent for the other formats. Any suggestions?
Edit: I forgot to mention that this needs to be cross-platform, so I can't fall back on outside tools.
I don't know of something which handles all formats, but you could do this with a shell call and a little bit of parsing of the result.
I have written a module that has some generic, reusable code that I would like to be able to use in other projects. Is there a place I could put this file on computer so that Ruby can find it regardless of where I saved the file that is including it? I am using a Mac.
There's no standard place to put code like this. You could put all your code in a gem and install the gem, or create a directory to put this code in. Once you create the directory, alter the LOAD_PATH global variable to include this directory. You can do this either in each script that uses these, or with the RUBYOPT environment variable. For example, you could put ~/my_ruby_stuff in your path and put your files there. One warning if you do that, make sure the path you add is at the end of the gem path and try to avoid any name conflicts with existing Ruby libraries or gems.
Consider making a "gem" out of your code. The advantages are: separate project, better defined interface, separate source control, can share with other developers in your company, etc