class Importer::Row

Attributes

errors[R]

Attributes

line[R]

Attributes

values[R]

Attributes

Public Class Methods

new(importer, line, value_hash = nil) click to toggle source
# File lib/iron/import/row.rb, line 11
def initialize(importer, line, value_hash = nil)
  @importer = importer
  @line = line
  set_values(value_hash)
  
  @errors = []
end

Public Instance Methods

[](column_key) click to toggle source

Returns the value of a column.

# File lib/iron/import/row.rb, line 49
def [](column_key)
  @values[column_key]
end
add_error(msg) click to toggle source
# File lib/iron/import/row.rb, line 64
def add_error(msg)
  @importer.add_error(msg, :row => self)
end
all?(*keys) click to toggle source

True when all columns have a non-nil value, useful in filtering out junk rows. Pass in one or more keys to check only those keys for presence.

# File lib/iron/import/row.rb, line 25
def all?(*keys)
  keys.flatten!
  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
empty?() click to toggle source

True when all row columns have nil values.

# File lib/iron/import/row.rb, line 44
def empty?
  @values.values.all?(&:nil?)
end
error_map() click to toggle source

Return a map of column key to Error, intended for use in error reporting.

# File lib/iron/import/row.rb, line 73
def error_map
  map = {}
  @errors.each do |err|
    map[err.column.key] = err
  end
  map
end
has_errors?() click to toggle source
# File lib/iron/import/row.rb, line 68
def has_errors?
  @errors && @errors.count > 0
end
set_values(value_hash) click to toggle source
# File lib/iron/import/row.rb, line 19
def set_values(value_hash)
  @values = value_hash
end
to_h() click to toggle source

This row's values as a hash of :column_key => <parsed + validated value>

# File lib/iron/import/row.rb, line 59
def to_h
  @values.dup
end
to_hash() click to toggle source
# File lib/iron/import/row.rb, line 62
def to_hash ; to_h ; end
to_s() click to toggle source

The row's name, e.g. 'Row 4'

# File lib/iron/import/row.rb, line 54
def to_s
  "Row #{@line}"
end