Archive for the 'Ruby' Category

Posted on October 7, 2006 at 12:29 pm

New in dbf-0.4.0:

  • Support for dBase III style memo files
  • Documentation in doc/readme.txt
  • Fixed that field lengths were being read as signed integers, when they be should be unsigned
  • Fixed skipping over deleted records

Thank you to everybody that submitted patches and test files. Keep ‘em coming.

Posted on September 28, 2006 at 10:25 am

Update_attributes is not very smart; it will update a record whether or not the hash you pass it contains any changed values. If you aren’t careful, you could end up with a ton of database writes for no reason. Try my update_attributes_if_changed method instead:

module ActiveRecord
  class Base

    def update_attributes_if_changed(hash)
      update_attributes(hash) if needs_update?(hash)
    end

    def needs_update?(hash)
      hash.stringify_keys!
      !attributes.dup.delete_if{|k,v| !hash.key?(k) || hash[k] == v}.empty?
    end

    def write_attributes(hash)
      attributes.merge(hash.stringify_keys)
    end

  end
end

I’ve thrown in a method called write_attributes too. It works just like update_attributes, but it doesn’t automatically save the record.

Posted on September 26, 2006 at 4:43 pm

Yesterday, somebody asked me if it’s possible to format the contents of an input field using the text_field form helper.

I don’t think its documented in the API docs, but you can specify the value to use by passing in a value parameter:

text_field :book, :title, :value => @book.title.upcase
Posted on August 1, 2006 at 6:21 pm

The DBF library project page is up:
http://rubyforge.org/projects/dbf/

There’s no documentation yet, but you should be able to figure out how to use it by looking at the unit tests.

You can download it from the project page as a gem or tar.gz or install it via rubygems:

gem install dbf
Posted on July 30, 2006 at 1:20 pm

I’ve written a DBF database access library in Ruby, but so far I’ve only tested it with files created with a couple of versions of FoxPro. I need files created with different flavors of DBase, XBase, Clipper, and FoxPro in order to flesh out the test suite. Ultimately, I would like to library to handle all the known variations of the DBF file format.

The project will be available on rubyforge.com within in a couple of days. I’ll post the link as soon as it’s available. The project is hosted on Rubyforge and can be found here.

If you have any files with the following characteristics, please email them to me at keithm@infused.org. Better yet, if you want to take the time to create a fresh sample database for me that would be awesome. Here’s what I’m looking for:

  • Small dataset. Prefer less than 100 rows
  • At least one field from each of the general data types. This means:
    • At least one Character field (if using software that supports fields larger than 254 characters, also include at least one field that is larger)
    • At least one Number field
    • At least one Boolean field
    • At least one Date field
    • At least one Memo field (please include the memo file along with the dbf file)
  • Fields to include if supported by the software:
    • At least one Floating Point field
    • At least one Binary, General, or Picture field (not neccessary to have one of each)
    • At least one Currency field
    • At least one Integer field
    • At lease one DateTime field
    • At lease one Timestamp field

There are a few other data types such as VariField which I don’t really care about right now.

Special Bonus Offer:
If you have access to 3 or more of the software packages and/or versions and are willing to create good sample databases I will pay you for your efforts. Contact me at the email above for details.