Skip to content

Commit

Permalink
fix merge
Browse files Browse the repository at this point in the history
  • Loading branch information
James McKinney committed Feb 5, 2015
2 parents 9130176 + 08ab3af commit 16aafbe
Show file tree
Hide file tree
Showing 12 changed files with 240 additions and 221 deletions.
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.1.4
24 changes: 21 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,26 @@ rvm:
notifications:
irc:
channels:
- "irc.freenode.net#theodi"
- irc.freenode.net#theodi
template:
- "%{repository} %{branch} - %{message} %{build_url}"
- '%{repository} %{branch} - %{message} %{build_url}'
on_success: change
on_failure: always
on_failure: always
deploy:
provider: rubygems
api_key:
secure: fjnPS61/skQ1PsRJu1SYWIct0vjdkTyQhj0ria9zfcJfbWbfiHnpehVh1ege3sTUkDSTvoOFT35jzEeozvtKZOlAWMU5QbL8LTXu+JSp9olOdSuGeWRWVuQT3NLgRJW0+2c7N66piZvnRUUTyt2P8VIR8c/Ltuhc32bUGL7X6Gw=
gem: csvlint
on:
tags: true
repo: theodi/csvlint.rb
all_branches: true
after_success:
- export GEM_VERSION=`ruby -e "puts Gem::Specification.load(Dir['*.gemspec'].first).version.to_s"`
- '[ "$TRAVIS_BRANCH" == "master" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && curl
-v -X POST -d ''{"ref":"refs/tags/''$GEM_VERSION''","sha":"''$TRAVIS_COMMIT''"}'' --header
"Content-Type:application/json" -u $GITHUB_USER:$GITHUB_PASSWORD "https://api.github.com/repos/$TRAVIS_REPO_SLUG/git/refs"'
env:
global:
- secure: hM8Pv/EAZoB4fGGEUwKQQ/2+mgKbUac+PH2cwud25l2MJ64eoKEMZzfy4TF6+XMIzXhlWpsg4s51y6K3+W8pUyRAuwo2MsN5Iee7HnLz+LlYTiT0//iQdAmxQ0JlOyh8vd2SEFBcVfwpp/iZFIHAfbBO73ZDXhtGMEieMk025I0=
- secure: hsKbZ0kVKVU/e8oVCPJpRmBxbbieN2tVbyjdhJo/UYchcyLWeGAmAj/ApUDL4SyR0HZxpfi+SIsGFNRy5LnrFeCFgY9aZ6u9ma4n0Y2cTElMRt5kvI/c28FehsRjCzAe6W8dxwhJ8wSkvFDNpLml47/iy8bw4a7aUZDdq3OYXck=
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Currently the gem supports retrieving a CSV accessible from a URL, File, or an I
require 'csvlint'

validator = Csvlint::Validator.new( "http://example.org/data.csv" )
validator = Csvlint::Validator.new( File.new("/path/to/my/data.csv" )
validator = Csvlint::Validator.new( File.new("/path/to/my/data.csv" ))
validator = Csvlint::Validator.new( StringIO.new( my_data_in_a_string ) )

When validating from a URL the range of errors and warnings is wider as the library will also check HTTP headers for
Expand Down Expand Up @@ -61,13 +61,13 @@ best practices
## Controlling CSV Parsing

The validator supports configuration of the [CSV Dialect](http://dataprotocols.org/csv-dialect/) used in a data file. This is specified by
passing an options hash to the constructor:
passing a dialect hash to the constructor:

opts = {
dialect = {
"header" => true,
"delimiter" => ","
}
validator = Csvlint::Validator.new( "http://example.org/data.csv", opts )
validator = Csvlint::Validator.new( "http://example.org/data.csv", dialect )

The options should be a Hash that conforms to the [CSV Dialect](http://dataprotocols.org/csv-dialect/) JSON structure.

Expand Down Expand Up @@ -205,6 +205,19 @@ Schema validation provides some additional types of error and warning messages:
* `:below_minimum` (error) -- a column with a `minimum` constraint contains a value that is below the minimum
* `:above_maximum` (error) -- a column with a `maximum` constraint contains a value that is above the maximum

## Other validation options

You can also provide an optional options hash as the fourth argument to Validator#new. Supported options are:

* :limit_lines -- only check this number of lines of the CSV file. Good for a quick check on huge files.

```
options = {
limit_lines: 100
}
validator = Csvlint::Validator.new( "http://example.org/data.csv", nil, nil, options )
```

## Contributing

1. Fork it
Expand Down
11 changes: 3 additions & 8 deletions features/support/env.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
require 'coveralls'
Coveralls.wear_merged!('test_frameworks')

$:.unshift File.join( File.dirname(__FILE__), "..", "..", "lib")

require 'simplecov'
require 'simplecov-rcov'
require 'rspec/expectations'
require 'csvlint'
require 'coveralls'
require 'pry'

Coveralls.wear_merged!

SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
SimpleCov.start

require 'spork'

Spork.each_run do
Expand Down
9 changes: 7 additions & 2 deletions lib/csvlint.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
require 'csv'
require 'date'
require 'open-uri'
require 'mime/types'
require 'set'
require 'tempfile'

require 'csvlint/types'
require 'active_support/core_ext/date/conversions'
require 'active_support/core_ext/time/conversions'
require 'mime/types'
require 'open_uri_redirections'

require 'csvlint/error_message'
require 'csvlint/error_collector'
require 'csvlint/validate'
Expand Down
69 changes: 68 additions & 1 deletion lib/csvlint/field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ module Csvlint

class Field
include Csvlint::ErrorCollector
include Csvlint::Types

attr_reader :name, :constraints, :title, :description

Expand Down Expand Up @@ -98,5 +97,73 @@ def convert_to_type(value)
end
return parsed
end

TYPE_VALIDATIONS = {
'http://www.w3.org/2001/XMLSchema#string' => lambda { |value, constraints| value },
'http://www.w3.org/2001/XMLSchema#int' => lambda { |value, constraints| Integer value },
'http://www.w3.org/2001/XMLSchema#integer' => lambda { |value, constraints| Integer value },
'http://www.w3.org/2001/XMLSchema#float' => lambda { |value, constraints| Float value },
'http://www.w3.org/2001/XMLSchema#double' => lambda { |value, constraints| Float value },
'http://www.w3.org/2001/XMLSchema#anyURI' => lambda do |value, constraints|
u = URI.parse value
raise ArgumentError unless u.kind_of?(URI::HTTP) || u.kind_of?(URI::HTTPS)
u
end,
'http://www.w3.org/2001/XMLSchema#boolean' => lambda do |value, constraints|
return true if ['true', '1'].include? value
return false if ['false', '0'].include? value
raise ArgumentError
end,
'http://www.w3.org/2001/XMLSchema#nonPositiveInteger' => lambda do |value, constraints|
i = Integer value
raise ArgumentError unless i <= 0
i
end,
'http://www.w3.org/2001/XMLSchema#negativeInteger' => lambda do |value, constraints|
i = Integer value
raise ArgumentError unless i < 0
i
end,
'http://www.w3.org/2001/XMLSchema#nonNegativeInteger' => lambda do |value, constraints|
i = Integer value
raise ArgumentError unless i >= 0
i
end,
'http://www.w3.org/2001/XMLSchema#positiveInteger' => lambda do |value, constraints|
i = Integer value
raise ArgumentError unless i > 0
i
end,
'http://www.w3.org/2001/XMLSchema#dateTime' => lambda do |value, constraints|
date_pattern = constraints["datePattern"] || "%Y-%m-%dT%H:%M:%SZ"
d = DateTime.strptime(value, date_pattern)
raise ArgumentError unless d.strftime(date_pattern) == value
d
end,
'http://www.w3.org/2001/XMLSchema#date' => lambda do |value, constraints|
date_pattern = constraints["datePattern"] || "%Y-%m-%d"
d = Date.strptime(value, date_pattern)
raise ArgumentError unless d.strftime(date_pattern) == value
d
end,
'http://www.w3.org/2001/XMLSchema#time' => lambda do |value, constraints|
date_pattern = constraints["datePattern"] || "%H:%M:%S"
d = DateTime.strptime(value, date_pattern)
raise ArgumentError unless d.strftime(date_pattern) == value
d
end,
'http://www.w3.org/2001/XMLSchema#gYear' => lambda do |value, constraints|
date_pattern = constraints["datePattern"] || "%Y"
d = Date.strptime(value, date_pattern)
raise ArgumentError unless d.strftime(date_pattern) == value
d
end,
'http://www.w3.org/2001/XMLSchema#gYearMonth' => lambda do |value, constraints|
date_pattern = constraints["datePattern"] || "%Y-%m"
d = Date.strptime(value, date_pattern)
raise ArgumentError unless d.strftime(date_pattern) == value
d
end,
}
end
end
2 changes: 0 additions & 2 deletions lib/csvlint/schema.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "set"

module Csvlint

class Schema
Expand Down
137 changes: 0 additions & 137 deletions lib/csvlint/types.rb

This file was deleted.

Loading

0 comments on commit 16aafbe

Please sign in to comment.