Class: CSVModel::Row
- Inherits:
-
Object
- Object
- CSVModel::Row
- Includes:
- Utilities::Options
- Defined in:
- lib/csv_model/row.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#marked_as_duplicate ⇒ Object
readonly
Returns the value of attribute marked_as_duplicate.
Attributes included from Utilities::Options
Instance Method Summary collapse
- #errors ⇒ Object
- #index(value) ⇒ Object (also: #[])
-
#initialize(header, data, options = {}) ⇒ Row
constructor
A new instance of Row.
- #key ⇒ Object
- #mark_as_duplicate ⇒ Object
- #marked_as_duplicate? ⇒ Boolean
- #status ⇒ Object
- #valid? ⇒ Boolean
Methods included from Utilities::Options
Constructor Details
#initialize(header, data, options = {}) ⇒ Row
Returns a new instance of Row.
9 10 11 12 13 |
# File 'lib/csv_model/row.rb', line 9 def initialize(header, data, = {}) @header = header @data = data @options = end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
7 8 9 |
# File 'lib/csv_model/row.rb', line 7 def data @data end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
7 8 9 |
# File 'lib/csv_model/row.rb', line 7 def header @header end |
#marked_as_duplicate ⇒ Object (readonly)
Returns the value of attribute marked_as_duplicate.
7 8 9 |
# File 'lib/csv_model/row.rb', line 7 def marked_as_duplicate @marked_as_duplicate end |
Instance Method Details
#errors ⇒ Object
21 22 23 24 25 26 |
# File 'lib/csv_model/row.rb', line 21 def errors errors = [] errors << duplicate_row_error if is_dry_run? && marked_as_duplicate? errors << model_instance.errors if !model_instance.valid? errors.flatten end |
#index(value) ⇒ Object Also known as: []
15 16 17 18 |
# File 'lib/csv_model/row.rb', line 15 def index(value) index = column_index(value) || value data[index] if index.is_a?(Fixnum) && index >= 0 end |
#key ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/csv_model/row.rb', line 28 def key cols = primary_key_columns if cols.one? index(cols.first.key) elsif cols.any? cols.collect { |x| index(x.key) } else data end end |
#mark_as_duplicate ⇒ Object
43 44 45 |
# File 'lib/csv_model/row.rb', line 43 def mark_as_duplicate @marked_as_duplicate = true end |
#marked_as_duplicate? ⇒ Boolean
39 40 41 |
# File 'lib/csv_model/row.rb', line 39 def marked_as_duplicate? !!marked_as_duplicate end |
#status ⇒ Object
47 48 49 |
# File 'lib/csv_model/row.rb', line 47 def status model_instance.status end |
#valid? ⇒ Boolean
51 52 53 |
# File 'lib/csv_model/row.rb', line 51 def valid? errors.empty? end |