quandl_format 0.1.1 → 0.1.2
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/format/dataset/attributes.rb +32 -1
- data/lib/quandl/format/errors.rb +3 -0
- data/lib/quandl/format/version.rb +1 -1
- data/quandl_format.gemspec +1 -1
- data/spec/fixtures/data/mismatched_columns.qdf +9 -0
- data/spec/fixtures/data/mismatched_rows.qdf +7 -0
- data/spec/fixtures/format.rb +2 -2
- data/spec/lib/quandl/client/dataset_spec.rb +9 -9
- data/spec/lib/quandl/format/dataset/errors_spec.rb +10 -0
- metadata +8 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d82a7ccd02fbe5b8359fd3906eb6c7b2598d3d72
|
4
|
+
data.tar.gz: 04d70cbdc92e2bc1be083ed81e4ccc79df33b631
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0260e134f074a1b908a7e6995f54d21aacdffea30ae3faf7da1484d7b74a611d180ad8b399c08c431b3a6a78a2a43d072a3d7d6f7f0eba0ac6d1c13edacb9f6
|
7
|
+
data.tar.gz: d9eaba2e40f27ba8a1897c1afe107bfa983a38e47af7978106f7bdcfd4d0b8281c3b5e7bebe468ec91de9c356a8a8e6bf9f1d0d34e75880fd3cc1730326732dd
|
data/UPGRADE.md
CHANGED
@@ -8,7 +8,7 @@ module Attributes
|
|
8
8
|
|
9
9
|
module ClassMethods
|
10
10
|
|
11
|
-
META_ATTRIBUTES = :source_code, :code, :name, :description, :private, :
|
11
|
+
META_ATTRIBUTES = :source_code, :code, :name, :description, :private, :reference_url
|
12
12
|
DATA_ATTRIBUTES = :column_names, :data
|
13
13
|
|
14
14
|
def attribute_names
|
@@ -61,6 +61,9 @@ module Attributes
|
|
61
61
|
def data=(rows)
|
62
62
|
self.column_names = rows.shift unless rows.first.collect{|r| r.to_s.numeric? }.include?(true)
|
63
63
|
@data = Quandl::Data.new(rows).to_date
|
64
|
+
data_row_count_should_match_column_count!
|
65
|
+
data_rows_should_have_equal_columns!
|
66
|
+
@data
|
64
67
|
end
|
65
68
|
|
66
69
|
def column_names=(names)
|
@@ -90,8 +93,36 @@ module Attributes
|
|
90
93
|
%Q{<##{self.class.name} #{attrs.join(', ')}>}
|
91
94
|
end
|
92
95
|
|
96
|
+
protected
|
97
|
+
|
98
|
+
def data_rows_should_have_equal_columns!
|
99
|
+
row_count = data[0].count
|
100
|
+
data.each_with_index do |row, index|
|
101
|
+
raise_row_column_mismatch!(row, index) unless row.count == row_count
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def data_row_count_should_match_column_count!
|
106
|
+
return if column_names.blank?
|
107
|
+
column_count = column_names.count
|
108
|
+
data.each_with_index do |row, index|
|
109
|
+
raise_column_count_mismatch!(row, index) unless row.count == column_count
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
|
93
114
|
private
|
94
115
|
|
116
|
+
def raise_row_column_mismatch!(row, index)
|
117
|
+
m = "ColumnCountMismatch #{full_code} data[0] had #{data[0].count} columns, but data[#{index}] had #{row.count} #{row}"
|
118
|
+
raise Quandl::Format::Errors::ColumnCountMismatch, m
|
119
|
+
end
|
120
|
+
|
121
|
+
def raise_column_count_mismatch!(row, index)
|
122
|
+
m = "ColumnCountMismatch #{full_code} column_names had #{column_names.count} columns, but data[#{index}] had #{row.count} #{row}"
|
123
|
+
raise Quandl::Format::Errors::ColumnCountMismatch, m
|
124
|
+
end
|
125
|
+
|
95
126
|
def raise_unknown_attribute_error!(key)
|
96
127
|
m = "UnknownAttribute #{key} recognized attributes are: #{self.class.attribute_names}"
|
97
128
|
raise Quandl::Format::Errors::UnknownAttribute, m
|
data/lib/quandl/format/errors.rb
CHANGED
data/quandl_format.gemspec
CHANGED
data/spec/fixtures/format.rb
CHANGED
@@ -43,7 +43,7 @@ def qdf_attributes
|
|
43
43
|
description: "Here is a description with multiple lines.\n This is the second line.",
|
44
44
|
column_names: ['Date', 'Value', 'High', 'Low'],
|
45
45
|
private: false,
|
46
|
-
|
46
|
+
reference_url: 'http://test.com/',
|
47
47
|
data: Quandl::Data.new([["2013-11-20", "9.99470588235294", "11.003235294117646", "14.00164705882353"],["2013-11-19", "10.039388096885814", nil, "14.09718770934256"]]),
|
48
48
|
}
|
49
49
|
end
|
@@ -56,7 +56,7 @@ description: |-
|
|
56
56
|
Here is a description with multiple lines.
|
57
57
|
This is the second line.
|
58
58
|
private: false
|
59
|
-
|
59
|
+
reference_url: http://test.com/
|
60
60
|
-
|
61
61
|
Date,Value,High,Low
|
62
62
|
2013-11-20,9.99470588235294,11.003235294117646,14.00164705882353
|
@@ -4,15 +4,15 @@ require 'spec_helper'
|
|
4
4
|
describe Quandl::Client::Dataset do
|
5
5
|
|
6
6
|
let(:attributes) { {
|
7
|
-
code:
|
8
|
-
source_code:
|
9
|
-
name:
|
10
|
-
description:
|
11
|
-
column_names:
|
12
|
-
private:
|
13
|
-
|
14
|
-
data:
|
15
|
-
|
7
|
+
code: 'DATASET_CODE_2',
|
8
|
+
source_code: 'SOURCE_CODE',
|
9
|
+
name: 'Test Dataset Name 2',
|
10
|
+
description: "Here is a description with multiple lines.\n This is the second line.",
|
11
|
+
column_names: ['Date', 'Value', 'High', 'Low'],
|
12
|
+
private: false,
|
13
|
+
reference_url: 'http://test.com/',
|
14
|
+
data: [["2013-11-20", "9.99470588235294", "11.003235294117646", "14.00164705882353"],
|
15
|
+
["2013-11-19", "10.039388096885814", nil, "14.09718770934256"]],
|
16
16
|
}}
|
17
17
|
|
18
18
|
subject{ Quandl::Client::Dataset.new( attributes ) }
|
@@ -29,4 +29,14 @@ describe Quandl::Format::Dataset do
|
|
29
29
|
it{ expect{data}.to raise_error Quandl::Format::Errors::UnknownAttribute, /this_attribute_does_not_exist/ }
|
30
30
|
end
|
31
31
|
|
32
|
+
context "mismatched_columns.qdf" do
|
33
|
+
let(:data){ Quandl::Format::Dataset.load( fixtures_data['mismatched_columns'] ) }
|
34
|
+
it{ expect{data}.to raise_error Quandl::Format::Errors::ColumnCountMismatch, /column_names had 4 columns/ }
|
35
|
+
end
|
36
|
+
|
37
|
+
context "mismatched_rows.qdf" do
|
38
|
+
let(:data){ Quandl::Format::Dataset.load( fixtures_data['mismatched_rows'] ) }
|
39
|
+
it{ expect{data}.to raise_error Quandl::Format::Errors::ColumnCountMismatch, /had 3 columns/ }
|
40
|
+
end
|
41
|
+
|
32
42
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quandl_format
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
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-
|
11
|
+
date: 2013-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -114,14 +114,14 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - ~>
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '2.
|
117
|
+
version: '2.3'
|
118
118
|
type: :runtime
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - ~>
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '2.
|
124
|
+
version: '2.3'
|
125
125
|
description: Data will be loaded and dumped.
|
126
126
|
email:
|
127
127
|
- blake@hilscher.ca
|
@@ -149,6 +149,8 @@ files:
|
|
149
149
|
- spec/config/client.rb
|
150
150
|
- spec/config/logger.rb
|
151
151
|
- spec/fixtures/data/invalid_data.qdf
|
152
|
+
- spec/fixtures/data/mismatched_columns.qdf
|
153
|
+
- spec/fixtures/data/mismatched_rows.qdf
|
152
154
|
- spec/fixtures/data/unknown_attribute.qdf
|
153
155
|
- spec/fixtures/data/valid.qdf
|
154
156
|
- spec/fixtures/format.rb
|
@@ -187,6 +189,8 @@ test_files:
|
|
187
189
|
- spec/config/client.rb
|
188
190
|
- spec/config/logger.rb
|
189
191
|
- spec/fixtures/data/invalid_data.qdf
|
192
|
+
- spec/fixtures/data/mismatched_columns.qdf
|
193
|
+
- spec/fixtures/data/mismatched_rows.qdf
|
190
194
|
- spec/fixtures/data/unknown_attribute.qdf
|
191
195
|
- spec/fixtures/data/valid.qdf
|
192
196
|
- spec/fixtures/format.rb
|