quandl_data 1.3.4 → 1.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/UPGRADE.md +7 -0
- data/lib/quandl/data/format.rb +37 -16
- data/lib/quandl/data/operations.rb +4 -0
- data/lib/quandl/data/validations.rb +36 -0
- data/lib/quandl/data/version.rb +1 -1
- data/lib/quandl/data.rb +3 -1
- data/lib/quandl/error/date_parse_error.rb +8 -0
- data/spec/lib/quandl/data/format_spec.rb +1 -1
- metadata +4 -3
- data/lib/quandl/error/unknown_date_format.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce1b13bea3abd317b83855932749d9b29836a838
|
4
|
+
data.tar.gz: dedc1c64c0354e3a1042a7662e8896090b45421a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea8568c09b7d551e35add9f272d7d48e7830b1ef2bda7aedbe54e76a4188dea0c939acf7862895e86a13a0b216b7fb757af993c0e5a72c8e45f1b9c155818cac
|
7
|
+
data.tar.gz: 4199b62dc28313abd1204de393dccdaf1aa4ffafc3512b340a32526d2859882020c096059b3bb0c47e1e90f65f2c74a97a9cd4d863eacd3e23ad052f98364ed5
|
data/UPGRADE.md
CHANGED
data/lib/quandl/data/format.rb
CHANGED
@@ -35,7 +35,7 @@ class Format
|
|
35
35
|
when :date then return data
|
36
36
|
when :date_string then return date_strings_to_date( data )
|
37
37
|
when :jd, :jd_string then return jds_to_date( data )
|
38
|
-
when :unknown then
|
38
|
+
when :unknown then raise_date_parse_error!( data[0] )
|
39
39
|
end
|
40
40
|
# return data
|
41
41
|
data
|
@@ -51,7 +51,7 @@ class Format
|
|
51
51
|
when :jd_string then return jd_strings_to_jd( data )
|
52
52
|
when :date then return dates_to_jd( data )
|
53
53
|
when :date_string then return date_strings_to_jd( data )
|
54
|
-
when :unknown then
|
54
|
+
when :unknown then raise_date_parse_error!( data[0] )
|
55
55
|
end
|
56
56
|
# return data
|
57
57
|
data
|
@@ -104,7 +104,7 @@ class Format
|
|
104
104
|
# otherwise cast string jds to int
|
105
105
|
output = []
|
106
106
|
data.each_with_index do |row, index|
|
107
|
-
output << parse_jd_string(row
|
107
|
+
output << parse_jd_string(row, index)
|
108
108
|
end
|
109
109
|
output
|
110
110
|
end
|
@@ -115,7 +115,7 @@ class Format
|
|
115
115
|
# otherwise cast string jds to int
|
116
116
|
output = []
|
117
117
|
data.each_with_index do |row, index|
|
118
|
-
row = parse_date_string(row
|
118
|
+
row = parse_date_string(row, index)
|
119
119
|
row[0] = row[0].jd
|
120
120
|
output << row
|
121
121
|
end
|
@@ -131,7 +131,7 @@ class Format
|
|
131
131
|
return data if data_missing_rows?(data) || data[0][0].is_a?(Date)
|
132
132
|
output = []
|
133
133
|
data.each_with_index do |row, index|
|
134
|
-
output << parse_jd(row
|
134
|
+
output << parse_jd(row, index)
|
135
135
|
end
|
136
136
|
output
|
137
137
|
end
|
@@ -142,7 +142,7 @@ class Format
|
|
142
142
|
# otherwise cast string jds to int
|
143
143
|
output = []
|
144
144
|
data.each_with_index do |row, index|
|
145
|
-
output << parse_date_string(row
|
145
|
+
output << parse_date_string(row, index)
|
146
146
|
end
|
147
147
|
output
|
148
148
|
end
|
@@ -178,42 +178,63 @@ class Format
|
|
178
178
|
|
179
179
|
protected
|
180
180
|
|
181
|
-
def parse_jd(row)
|
181
|
+
def parse_jd(row, index=nil)
|
182
182
|
# parse jd_string
|
183
|
-
row = parse_jd_string(row)
|
183
|
+
row = parse_jd_string(row, index)
|
184
184
|
# jd to date
|
185
185
|
row[0] = Date.jd( row[0] )
|
186
186
|
# onwards
|
187
187
|
row
|
188
|
+
rescue => e
|
189
|
+
raise_jd_error!(row, index, e)
|
188
190
|
end
|
189
191
|
|
190
|
-
def parse_jd_string(row)
|
192
|
+
def parse_jd_string(row, index=nil)
|
191
193
|
row = row.dup
|
192
194
|
row[0] = row[0].to_i
|
193
195
|
# dont allow dates that are before 0000
|
194
|
-
raise
|
196
|
+
raise if row[0] <= 1721058
|
197
|
+
# onwards
|
195
198
|
row
|
199
|
+
rescue => e
|
200
|
+
raise_jd_string_error!(row, index, e)
|
196
201
|
end
|
197
202
|
|
198
|
-
def parse_date_string(row)
|
203
|
+
def parse_date_string(row, index=nil)
|
199
204
|
row = row.dup
|
200
205
|
# extract date
|
201
206
|
date = row[0]
|
202
207
|
# split date into parts
|
203
208
|
date_values = date.split('-').collect(&:to_i)
|
204
|
-
# ensure
|
205
|
-
raise
|
209
|
+
# ensure valid
|
210
|
+
raise unless date_values.count == 3
|
206
211
|
# add to row
|
207
212
|
row[0] = Date.new( *date_values )
|
208
213
|
row
|
214
|
+
rescue => e
|
215
|
+
raise_date_string_error!(row, index, e)
|
209
216
|
end
|
210
217
|
|
211
218
|
|
212
219
|
private
|
213
220
|
|
214
|
-
def
|
215
|
-
|
216
|
-
|
221
|
+
def raise_jd_error!(row, index, err)
|
222
|
+
raise Quandl::Error::DateParseError.new( line: index, context: 'parse_jd', row: row, problem: err.message ), err.message
|
223
|
+
end
|
224
|
+
|
225
|
+
def raise_jd_string_error!(row, index, err)
|
226
|
+
m = "Julian Date predates time. Expected <= 1721058 received '#{row[0]}'"
|
227
|
+
raise Quandl::Error::DateParseError.new( line: index, context: 'parse_jd_string', row: row, problem: m ), m
|
228
|
+
end
|
229
|
+
|
230
|
+
def raise_date_string_error!(row, index, err)
|
231
|
+
m = "Invalid date segments. Expected yyyy-mm-dd received '#{row[0]}'"
|
232
|
+
raise Quandl::Error::DateParseError.new({ line: index, context: 'parse_date_string', row: row, problem: m }), m
|
233
|
+
end
|
234
|
+
|
235
|
+
def raise_date_parse_error!(row, index = 0, type = :none)
|
236
|
+
m = "'#{row[0]}', index: data[#{index}][0] strategy: '#{type}', row: '#{row}'"
|
237
|
+
raise Quandl::Error::DateParseError.new({ line: index, context: 'date_parse_error', row: row, problem: m }), m
|
217
238
|
end
|
218
239
|
|
219
240
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Quandl
|
2
|
+
class Data
|
3
|
+
module Validations
|
4
|
+
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
included do
|
12
|
+
ERROR_TYPES = [
|
13
|
+
Error::GuessDateFormat, Error::InvalidDate,
|
14
|
+
Error::UnknownDateFormat, Error::DateParseError ]
|
15
|
+
end
|
16
|
+
|
17
|
+
def valid?
|
18
|
+
self.errors = []
|
19
|
+
self.data_array = pristine_data
|
20
|
+
true
|
21
|
+
rescue *ERROR_TYPES => error
|
22
|
+
self.errors << error
|
23
|
+
self.data_array = []
|
24
|
+
false
|
25
|
+
end
|
26
|
+
|
27
|
+
def errors
|
28
|
+
@errors ||= []
|
29
|
+
end
|
30
|
+
def errors=(value)
|
31
|
+
@errors = value
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/quandl/data/version.rb
CHANGED
data/lib/quandl/data.rb
CHANGED
@@ -9,13 +9,14 @@ require "quandl/operation"
|
|
9
9
|
|
10
10
|
require 'quandl/babelfish'
|
11
11
|
|
12
|
-
require 'quandl/error/
|
12
|
+
require 'quandl/error/date_parse_error'
|
13
13
|
|
14
14
|
require 'quandl/data/attributes'
|
15
15
|
require 'quandl/data/cleaning'
|
16
16
|
require 'quandl/data/enumerator'
|
17
17
|
require 'quandl/data/operations'
|
18
18
|
require 'quandl/data/format'
|
19
|
+
require 'quandl/data/validations'
|
19
20
|
require 'quandl/data/logging'
|
20
21
|
|
21
22
|
module Quandl
|
@@ -24,6 +25,7 @@ class Data
|
|
24
25
|
include Cleaning
|
25
26
|
include Enumerator
|
26
27
|
include Operations
|
28
|
+
include Validations
|
27
29
|
include Logging if defined?(QUANDL_LOGGER) && QUANDL_LOGGER == true
|
28
30
|
end
|
29
31
|
end
|
@@ -72,7 +72,7 @@ describe Quandl::Data::Format do
|
|
72
72
|
|
73
73
|
[:invalid1, :invalid2].each do |type|
|
74
74
|
it "#{type} should raise Quandl::Error::UnknownDateFormat" do
|
75
|
-
expect { Quandl::Data::Format.parse( self.send(type) ) }.to raise_error Quandl::Error::
|
75
|
+
expect { Quandl::Data::Format.parse( self.send(type) ) }.to raise_error Quandl::Error::DateParseError
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quandl_data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Blake Hilscher
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: quandl_operation
|
@@ -160,8 +160,9 @@ files:
|
|
160
160
|
- lib/quandl/data/format.rb
|
161
161
|
- lib/quandl/data/logging.rb
|
162
162
|
- lib/quandl/data/operations.rb
|
163
|
+
- lib/quandl/data/validations.rb
|
163
164
|
- lib/quandl/data/version.rb
|
164
|
-
- lib/quandl/error/
|
165
|
+
- lib/quandl/error/date_parse_error.rb
|
165
166
|
- lib/quandl/fabricate.rb
|
166
167
|
- lib/quandl/fabricate/data.rb
|
167
168
|
- quandl_data.gemspec
|