Sha256: 6f3013a6c9952b86ff6c7a6d59de53bbf35e0ab87f0aa4c9d15a735a3bfc2654

Contents?: true

Size: 1.65 KB

Versions: 2

Compression:

Stored size: 1.65 KB

Contents

require 'digest/md5'
require 'iconv'
require 'uri'
require 'tmpdir'
require 'active_support'
require 'active_support/version'
%w{
  active_support/core_ext/object/blank
  active_support/core_ext/string/inflections
  active_support/core_ext/array/wrap
  active_support/core_ext/hash/except
}.each do |active_support_3_requirement|
  require active_support_3_requirement
end if ActiveSupport::VERSION::MAJOR == 3
require 'fastercsv'
require 'slither'
require 'roo'
I_KNOW_I_AM_USING_AN_OLD_AND_BUGGY_VERSION_OF_LIBXML2 = true
require 'nokogiri'
require 'remote_table/transform'
require 'remote_table/request'
require 'remote_table/package'
require 'remote_table/file'
require 'remote_table/file/csv'
require 'remote_table/file/fixed_width'
require 'remote_table/file/roo_spreadsheet'
require 'remote_table/file/ods'
require 'remote_table/file/xls'
require 'remote_table/file/html'

class RemoteTable
  attr_accessor :request, :package, :file, :transform
  attr_accessor :table
  
  def initialize(bus)
    @transform = Transform.new(bus)
    @package = Package.new(bus)
    @request = Request.new(bus)
    @file = File.new(bus)
  end
  
  def each
    finish_table! unless table
    table.each_row { |row| yield row }
  end
  alias :each_row :each
  
  def to_a
    cache_rows! if @_row_cache.nil?
    @_row_cache
  end
  alias :rows :to_a
  
  private
  
  def finish_table!
    package_path = request.download
    file_path = package.stage(package_path)
    raw_table = file.tabulate(file_path)
    self.table = transform.apply(raw_table) # must return something that responds to each_row
  end
  
  def cache_rows!
    @_row_cache = []
    each_row { |row| @_row_cache << row }
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
remote_table-0.2.15 lib/remote_table.rb
remote_table-0.2.14 lib/remote_table.rb