Module: JsonTableSchema::Data
- Included in:
- Schema
- Defined in:
- lib/jsontableschema/data.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Instance Method Summary collapse
- #cast_row(row, fail_fast = true) ⇒ Object (also: #convert_row)
- #cast_rows(rows, fail_fast = true, limit = nil) ⇒ Object (also: #convert)
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
4 5 6 |
# File 'lib/jsontableschema/data.rb', line 4 def errors @errors end |
Instance Method Details
#cast_row(row, fail_fast = true) ⇒ Object Also known as: convert_row
25 26 27 28 29 30 31 32 33 |
# File 'lib/jsontableschema/data.rb', line 25 def cast_row(row, fail_fast = true) @errors ||= [] raise_header_error(row) if row.count != fields.count fields.each_with_index do |field,i| row[i] = cast_column(field, row[i], fail_fast) end check_for_errors row end |
#cast_rows(rows, fail_fast = true, limit = nil) ⇒ Object Also known as: convert
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/jsontableschema/data.rb', line 6 def cast_rows(rows, fail_fast = true, limit = nil) @errors ||= [] parsed_rows = [] rows.each_with_index do |r, i| begin break if limit && (limit <= i) r = r.fields if r.class == CSV::Row parsed_rows << cast_row(r, fail_fast) rescue MultipleInvalid, ConversionError => e raise e if fail_fast == true @errors << e if e.is_a?(ConversionError) end end check_for_errors parsed_rows end |