Class: Importer::Row

Inherits:
Object
  • Object
show all
Defined in:
lib/iron/import/row.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sheet, line, value_hash = nil) ⇒ Row

Returns a new instance of Row.



7
8
9
10
11
# File 'lib/iron/import/row.rb', line 7

def initialize(sheet, line, value_hash = nil)
  @sheet = sheet
  @line = line
  @values = value_hash
end

Instance Attribute Details

#lineObject (readonly)

Returns the value of attribute line.



5
6
7
# File 'lib/iron/import/row.rb', line 5

def line
  @line
end

#sheetObject (readonly)

Returns the value of attribute sheet.



5
6
7
# File 'lib/iron/import/row.rb', line 5

def sheet
  @sheet
end

#valuesObject (readonly)

Returns the value of attribute values.



5
6
7
# File 'lib/iron/import/row.rb', line 5

def values
  @values
end

Instance Method Details

#[](column_key) ⇒ Object

Returns the value of a column



41
42
43
# File 'lib/iron/import/row.rb', line 41

def [](column_key)
  @values[column_key]
end

#add_error(msg) ⇒ Object



49
50
51
# File 'lib/iron/import/row.rb', line 49

def add_error(msg)
  @sheet.importer.add_error(self, msg)
end

#add_warning(msg) ⇒ Object



53
54
55
# File 'lib/iron/import/row.rb', line 53

def add_warning(msg)
  @sheet.importer.add_warning(self, msg)
end

#all?(*keys) ⇒ Boolean

True when all columns have a non-nil value, useful in filtering out junk rows

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/iron/import/row.rb', line 19

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

#empty?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/iron/import/row.rb', line 36

def empty?
  @values.values.all?(&:nil?)
end

#set_values(value_hash) ⇒ Object



13
14
15
# File 'lib/iron/import/row.rb', line 13

def set_values(value_hash)
  @values = value_hash
end

#to_sObject



45
46
47
# File 'lib/iron/import/row.rb', line 45

def to_s
  "Row #{@line}"
end