Sha256: 8d445e3d63aca80dc085ecb4cb180cea2bd2736f889c9ed932b690e75ede807d

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

#
# h2. lib/imw/dataset/loaddump.rb -- read and write datasets to resources
#
# == About
#
# Implements methods to load a dataset from a resource and to write a
# dataset back to a resource.
#
# Author::    (Philip flip Kromer, Dhruv Bansal) for Infinite Monkeywrench Project (mailto:coders@infochimps.org)
# Copyright:: Copyright (c) 2008 infochimps.org
# License::   GPL 3.0
# Website::   http://infinitemonkeywrench.org/
#
# puts "#{File.basename(__FILE__)}: Something clever" # at bottom

require 'imw/utils'

module IMW
  class Dataset

    # Return the data in +filename+ in an appropriate form.
    #
    # FIXME How do I get pass a block from one method to another?
    def self.load filename, &block
      filename = path_to(filename)      
      announce "Loading #{filename}"
      file = IMW.open(filename)
      data = file.load(filename)
      if block
        data.each{|record| yield record}
        file
      else
        data
      end
    end

    # Dump +data+ to +filename+.
    def self.dump data, filename
      filename = path_to(filename)
      announce "Dumping to #{filename}"
      IMW.open(filename,'w').dump(data)
    end

    # Dispatch to <tt>Dataset.dump</tt>.
    def dump filename
      self.class.dump self.data, *args
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
imw-0.1.0 lib/imw/dataset/loaddump.rb