Module: JsonTableSchema::Data

Included in:
Schema
Defined in:
lib/jsontableschema/data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#errorsObject (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(field_name, value) ⇒ Object



30
31
32
# File 'lib/jsontableschema/data.rb', line 30

def cast(field_name, value)
  convert_column(value, get_field(field_name), true)
end

#convert(rows, fail_fast = true) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/jsontableschema/data.rb', line 6

def convert(rows, fail_fast = true)
  @errors ||= []
  rows.map! do |r|
    begin
      convert_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
  rows
end

#convert_row(row, fail_fast = true) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/jsontableschema/data.rb', line 20

def convert_row(row, fail_fast = true)
  @errors ||= []
  raise_header_error(row) if row.count != fields.count
  fields.each_with_index do |field,i|
    row[i] = convert_column(row[i], field, fail_fast)
  end
  check_for_errors
  row
end