filetype_validation 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/filetype_validation/csv_validator.rb +7 -4
- 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: a938a1467a255f48672027f5e59ee1f3653ac14f
|
4
|
+
data.tar.gz: 9e9d8ff18f5fc5db51e0cedf8614ea8821f32f95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e650852e7d10c8d76210a0d98bf180f79a54cfa4a76d3e6a476e46e1c9880f9abe5a98a5b8f4bb6f21a07a97d345a8843d72bfa609c8dcc4ed0c3df04ff9e63
|
7
|
+
data.tar.gz: 1b241d88e21174e10fc3c9782ccf1300d0769255e4d1fe00de8e1ea585c65988cfb6642ff4c8beb0a79ba87cbbc219b1dfbe38adcb981a6222b832f7d6b4fed9
|
@@ -4,8 +4,9 @@ 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
|
7
|
+
MAX_LINES = 25
|
8
|
+
HEADERS = true
|
9
|
+
UTF_OPTIONS = { invalid: :replace, undef: :replace, replace: '' }.freeze
|
9
10
|
|
10
11
|
# Evaluates whether the file is a csv
|
11
12
|
#
|
@@ -35,10 +36,12 @@ module FiletypeValidation
|
|
35
36
|
file_sample = File.foreach(file.path)
|
36
37
|
.first(options[:max_lines] || MAX_LINES)
|
37
38
|
.join
|
38
|
-
|
39
|
+
.encode('UTF-16', UTF_OPTIONS)
|
40
|
+
.encode('UTF-8', UTF_OPTIONS)
|
39
41
|
|
42
|
+
CSV.parse(file_sample, headers: options[:headers] || HEADERS)
|
40
43
|
true
|
41
|
-
rescue
|
44
|
+
rescue CSV::MalformedCSVError
|
42
45
|
false
|
43
46
|
end
|
44
47
|
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.4
|
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-
|
11
|
+
date: 2016-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|