Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/csvlint/csvw/column.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def validate_header(header, strict)
reset
if strict || @titles
valid_headers = @titles ? @titles.map{ |l,v| v if Column.languages_match(l, lang) }.flatten : []
unless valid_headers.include? header
unless valid_headers.empty? or valid_headers.include? header
if strict
build_errors(:invalid_header, :schema, 1, @number, header, @titles)
else
Expand Down
2 changes: 2 additions & 0 deletions lib/csvlint/csvw/table_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def initialize(url, id: nil, tables: {}, notes: [], annotations: {}, warnings: [
def validate_header(header, table_url, strict)
reset
table_url = "file:#{File.absolute_path(table_url)}" if table_url.instance_of? File
table_url = tables.keys[0] if table_url.instance_of? StringIO
table = tables[table_url]
table.validate_header(header, strict)
@errors += table.errors
Expand All @@ -33,6 +34,7 @@ def validate_header(header, table_url, strict)
def validate_row(values, row=nil, all_errors=[], table_url, validate)
reset
table_url = "file:#{File.absolute_path(table_url)}" if table_url.instance_of? File
table_url = tables.keys[0] if table_url.instance_of? StringIO
@validated_tables[table_url] = true
table = tables[table_url]
table.validate_row(values, row, validate)
Expand Down
36 changes: 36 additions & 0 deletions test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require 'csvlint'
require 'stringio'
require 'json'

csv_schema = <<JSON
{
"@context": "http://www.w3.org/ns/csvw",
"null": true,
"tables": [{
"url1": "naplan_student_csv_csvw.csv",
"tableSchema": {
"columns": [
{"name": "LocalId", "datatype": {"base": "string"}},
{"name": "FamilyName", "datatype": {"base": "string"}},
{"name": "GivenName", "datatype": {"base": "string"}},
{"name": "Homegroup", "datatype": {"base": "string"}},
{"name": "ClassCode", "datatype": {"base": "string"}},
{"name": "ASLSchoolId", "datatype": {"base": "string"}},
{"name": "SchoolLocalId", "datatype": {"base": "string"}},
{"name": "LocalCampusId", "datatype": {"base": "string"}},
{"name": "EmailAddress", "datatype": {"base": "string"}},
{"name": "ReceiveAdditionalInformation", "datatype": {"base": "boolean", "format": "Y|N"}},
{"name": "StaffSchoolRole", "datatype": {"base": "string"}}
]}}]
}
JSON
require 'json'
csv_schema = Csvlint::Schema.from_csvw_metadata("http://example.com", JSON.parse(csv_schema))
csv = <<CSV
LocalId,GivenName,FamilyName,Homegroup,ClassCode,ASLSchoolId,SchoolLocalId,LocalCampusId,EmailAddress,ReceiveAdditionalInformation,StaffSchoolRole
fjghh371,Treva,Seefeldt,7E,"7D,7E",knptb460,046129,01,[email protected],Y,teacher
CSV

validator = Csvlint::Validator.new( StringIO.new( csv ) , {}, csv_schema)
puts "a" if validator.valid?
validator.errors.each {|e| puts "Row: #{e.row} Col: #{e.column}, Category #{e.category}: Type #{e.type}, Content #{e.content}, Constraints: #{e.constraints}" }