Class: StrongCSV::Row
- Inherits:
-
Object
- Object
- StrongCSV::Row
- Extended by:
- Forwardable
- Defined in:
- lib/strong_csv/row.rb
Overview
Row is a representation of a row in a CSV file, which has casted values with specified types.
Instance Attribute Summary collapse
- #errors ⇒ Hash readonly
- #lineno ⇒ Integer readonly
Instance Method Summary collapse
-
#initialize(row:, types:, lineno:) ⇒ Row
constructor
A new instance of Row.
-
#valid? ⇒ Boolean
It returns true if the row has no errors.
Constructor Details
#initialize(row:, types:, lineno:) ⇒ Row
Returns a new instance of Row.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/strong_csv/row.rb', line 19 def initialize(row:, types:, lineno:) @values = {} @errors = {} @lineno = lineno types.each do |wrapper| cell = row[wrapper.name] @values[wrapper.name], error = wrapper.cast(cell) @errors[wrapper.name] = error if error end end |
Instance Attribute Details
#errors ⇒ Hash (readonly)
11 12 13 |
# File 'lib/strong_csv/row.rb', line 11 def errors @errors end |
#lineno ⇒ Integer (readonly)
14 15 16 |
# File 'lib/strong_csv/row.rb', line 14 def lineno @lineno end |
Instance Method Details
#valid? ⇒ Boolean
It returns true if the row has no errors.
33 34 35 |
# File 'lib/strong_csv/row.rb', line 33 def valid? @errors.empty? end |