Skip to content

Commit

Permalink
Rename cast to cast_rows
Browse files Browse the repository at this point in the history
  • Loading branch information
pezholio committed Oct 11, 2016
1 parent fbe4764 commit 98b9a30
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/jsontableschema/data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def load_fields!
self['fields'] = (self['fields'] || []).map { |f| JsonTableSchema::Field.new(f) }
end

def cast(rows, fail_fast = true)
def cast_rows(rows, fail_fast = true)
@errors ||= []
rows.map! do |r|
begin
Expand All @@ -21,7 +21,7 @@ def cast(rows, fail_fast = true)
rows
end

alias_method :convert, :cast
alias_method :convert, :cast_rows

def cast_row(row, fail_fast = true)
@errors ||= []
Expand Down
2 changes: 1 addition & 1 deletion lib/jsontableschema/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def csv_options
def rows(opts = {})
fail_fast = opts[:fail_fast] || opts[:fail_fast].nil?
rows = opts[:limit] ? @csv.to_a.drop(1).take(opts[:limit]) : @csv.to_a.drop(1)
converted = @schema.cast(rows, fail_fast)
converted = @schema.cast_rows(rows, fail_fast)
opts[:keyed] ? coverted_to_hash(@csv.headers, converted) : converted
end

Expand Down
12 changes: 6 additions & 6 deletions spec/data_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@

end

context 'convert' do
context 'cast_rows' do

it 'converts valid data' do
rows = [
Expand All @@ -109,7 +109,7 @@
['string', '10.0', '1', 'string', 'string']
]

converted_rows = schema.cast(rows)
converted_rows = schema.cast_rows(rows)

converted_rows.each do |row|
expect(row).to eq(['string', Float(10.0), 1, 'string', 'string'])
Expand All @@ -125,7 +125,7 @@
['string', '10.0', 'integer', 'string', 'string']
]

expect { schema.cast(rows) }.to raise_error(
expect { schema.cast_rows(rows) }.to raise_error(
JsonTableSchema::InvalidCast,
'not is not a number'
)
Expand All @@ -140,7 +140,7 @@
['string', '10.0', 'integer', 'string', 'string']
]

expect { schema.cast(rows, false) }.to raise_error(
expect { schema.cast_rows(rows, false) }.to raise_error(
JsonTableSchema::MultipleInvalid,
'There were errors parsing the data'
)
Expand All @@ -156,7 +156,7 @@
['string', '10.0', '1', 'string', 'string']
]

expect { schema.cast(rows, false) }.to raise_error(
expect { schema.cast_rows(rows, false) }.to raise_error(
JsonTableSchema::MultipleInvalid,
'There were errors parsing the data'
)
Expand All @@ -172,7 +172,7 @@
['string', '10.0', '1', 'string', 'string']
]

expect { schema.cast(rows) }.to raise_error(
expect { schema.cast_rows(rows) }.to raise_error(
JsonTableSchema::ConversionError,
'The number of items to convert (4) does not match the number of headers in the schema (5)'
)
Expand Down

0 comments on commit 98b9a30

Please sign in to comment.