Class: Importer::Row
- Inherits:
-
Object
- Object
- Importer::Row
- Defined in:
- lib/iron/import/row.rb
Instance Attribute Summary collapse
-
#line ⇒ Object
readonly
Returns the value of attribute line.
-
#sheet ⇒ Object
readonly
Returns the value of attribute sheet.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
-
#[](column_key) ⇒ Object
Returns the value of a column.
- #add_error(msg) ⇒ Object
- #add_warning(msg) ⇒ Object
-
#all?(*keys) ⇒ Boolean
True when all columns have a non-nil value, useful in filtering out junk rows.
- #empty? ⇒ Boolean
-
#initialize(sheet, line, value_hash = nil) ⇒ Row
constructor
A new instance of Row.
- #set_values(value_hash) ⇒ Object
- #to_s ⇒ Object
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
#line ⇒ Object (readonly)
Returns the value of attribute line.
5 6 7 |
# File 'lib/iron/import/row.rb', line 5 def line @line end |
#sheet ⇒ Object (readonly)
Returns the value of attribute sheet.
5 6 7 |
# File 'lib/iron/import/row.rb', line 5 def sheet @sheet end |
#values ⇒ Object (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
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
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_s ⇒ Object
45 46 47 |
# File 'lib/iron/import/row.rb', line 45 def to_s "Row #{@line}" end |