Sha256: e0ceb94e0cf316aff7a330df3d01f6c2b98eb55466cb67ad2bc7cc3e80b9aa7e

Contents?: true

Size: 1.15 KB

Versions: 3

Compression:

Stored size: 1.15 KB

Contents

class Importer
  
  class Row

    attr_reader :sheet, :line, :values
    
    def initialize(sheet, line, value_hash = nil)
      @sheet = sheet
      @line = line
      @values = value_hash
    end
    
    def set_values(value_hash)
      @values = value_hash
    end
    
    # True when all columns have a non-nil value, useful in filtering out junk 
    # rows
    def all?(*keys)
      if keys.any?
        # Check only the specified keys
        valid = true
        keys.each do |key|
          unless @values.has_key?(key)
            raise "Unknown column key :#{key} in call to Row#all?"
          end
          valid = valid && !@values[key].nil?
        end
        valid
      else
        # Check all value keys
        @values.values.all? {|v| !v.nil? }
      end
    end
    
    def empty?
      @values.values.all?(&:nil?)
    end
    
    # Returns the value of a column
    def [](column_key)
      @values[column_key]
    end
    
    def to_s
      "Row #{@line}"
    end
    
    def add_error(msg)
      @sheet.importer.add_error(self, msg)
    end
    
    def add_warning(msg)
      @sheet.importer.add_warning(self, msg)
    end
    
  end
  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
iron-import-0.6.1 lib/iron/import/row.rb
iron-import-0.6.0 lib/iron/import/row.rb
iron-import-0.5.0 lib/iron/import/row.rb