filetype_validation 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/filetype_validation/csv_validator.rb +9 -7
- data/lib/filetype_validation/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67e97bd93bc8490382a805ec0dc9db6566e75965
|
4
|
+
data.tar.gz: 1d13dc0fa63221c753914b91903ad7570be7d2cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a4e5f9465cb41aab4f7bee318b5c849f10c9a78afa0ff721d557a54ae756da2e46d36f026b068c5f1c4d14b342288b817bae92447a4871379e71d3cde669ede
|
7
|
+
data.tar.gz: 941ea67c3e76f1ad457654ee9652c878138b0d3698bfad61329208735be4672689dcb7ea6ce6a4217b787c3e8a08c9c5dc11c74e7a17678af0854a7eaa14e5f2
|
@@ -4,15 +4,15 @@ require 'filetype_validation/base_validator'
|
|
4
4
|
module FiletypeValidation
|
5
5
|
# aka Comma Separated Valuedator <--- hahahahhahah
|
6
6
|
class CsvValidator < BaseValidator
|
7
|
-
MAX_LINES
|
8
|
-
HEADERS
|
9
|
-
UTF_OPTIONS = { invalid: :replace, undef: :replace, replace: '' }.freeze
|
7
|
+
MAX_LINES = 25
|
8
|
+
HEADERS = true
|
10
9
|
|
11
10
|
# Evaluates whether the file is a csv
|
12
11
|
#
|
13
12
|
# @return [Boolean] true if it's a csv file
|
14
13
|
def valid?
|
15
|
-
csv_extension? &&
|
14
|
+
csv_extension? &&
|
15
|
+
FiletypeValidation.plaintext?(file, options) &&
|
16
16
|
parse_csv?
|
17
17
|
end
|
18
18
|
|
@@ -36,13 +36,15 @@ module FiletypeValidation
|
|
36
36
|
file_sample = File.foreach(file.path)
|
37
37
|
.first(options[:max_lines] || MAX_LINES)
|
38
38
|
.join
|
39
|
-
.encode('UTF-16', UTF_OPTIONS)
|
40
|
-
.encode('UTF-8', UTF_OPTIONS)
|
41
39
|
|
42
40
|
CSV.parse(file_sample, headers: options[:headers] || HEADERS)
|
43
41
|
true
|
42
|
+
rescue ArgumentError
|
43
|
+
# TODO: false, 'Invalid character on line ?.'
|
44
|
+
true
|
44
45
|
rescue CSV::MalformedCSVError
|
45
|
-
false
|
46
|
+
# TODO: false, 'Unclosed quoted field on line ?.'
|
47
|
+
true
|
46
48
|
end
|
47
49
|
end
|
48
50
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filetype_validation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe Jacob
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|