quandl_format 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ad3832ba8c845b964918c1fbb0db97aa2b1c6d65
4
- data.tar.gz: bf04d0d7c58742f9919cd6299bb4a4127c3043ed
3
+ metadata.gz: d82a7ccd02fbe5b8359fd3906eb6c7b2598d3d72
4
+ data.tar.gz: 04d70cbdc92e2bc1be083ed81e4ccc79df33b631
5
5
  SHA512:
6
- metadata.gz: bf602fb5d34d66077ca55c2202c267580e4d9bca78bad7b53e8b212fa7b07f00d5604cacb630c4735992d3efb8ba5c63f4f134ddd1e6e502f20e6a2a8a4751d8
7
- data.tar.gz: 00dcfaae4b866d13ed4855650cac709fdbad29a706886515b5c5c7d5e2d8ceafc82c52d7a937dc386d2001c83b204d1ee4f22635f1564d64bf1f58f213487c84
6
+ metadata.gz: e0260e134f074a1b908a7e6995f54d21aacdffea30ae3faf7da1484d7b74a611d180ad8b399c08c431b3a6a78a2a43d072a3d7d6f7f0eba0ac6d1c13edacb9f6
7
+ data.tar.gz: d9eaba2e40f27ba8a1897c1afe107bfa983a38e47af7978106f7bdcfd4d0b8281c3b5e7bebe468ec91de9c356a8a8e6bf9f1d0d34e75880fd3cc1730326732dd
data/UPGRADE.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## 0.1.2
2
+
3
+ * mismatched columns should raise ColumnCountMismatch
4
+ * revise specs to take reference_url instead of display_url
5
+ * revise attribute display_url to reference_url
6
+
7
+
1
8
  ## 0.1.0
2
9
 
3
10
  * only update client attrs before upload
@@ -8,7 +8,7 @@ module Attributes
8
8
 
9
9
  module ClassMethods
10
10
 
11
- META_ATTRIBUTES = :source_code, :code, :name, :description, :private, :display_url
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
@@ -1,7 +1,10 @@
1
1
  module Quandl
2
2
  module Format
3
3
  module Errors
4
+
4
5
  class UnknownAttribute < StandardError; end
6
+ class ColumnCountMismatch < StandardError; end
7
+
5
8
  end
6
9
  end
7
10
  end
@@ -1,5 +1,5 @@
1
1
  module Quandl
2
2
  module Format
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
@@ -25,6 +25,6 @@ Gem::Specification.new do |s|
25
25
  s.add_development_dependency "guard"
26
26
  s.add_development_dependency "guard-rspec"
27
27
 
28
- s.add_runtime_dependency "quandl_client", "~> 2.2"
28
+ s.add_runtime_dependency "quandl_client", "~> 2.3"
29
29
 
30
30
  end
@@ -0,0 +1,9 @@
1
+ code: "BLAKE_TEST_1"
2
+ name: "A new title"
3
+ description: "The description Date, Open, High"
4
+ private: false
5
+ -
6
+ Date,Open,High,Low
7
+ 2013-11-22,10,20,30
8
+ 2013-11-21,10,20,30,40
9
+ 2013-11-20,10,20,30
@@ -0,0 +1,7 @@
1
+ code: "BLAKE_TEST_2"
2
+ name: "A new title"
3
+ description: "The description Date, Open, High"
4
+ -
5
+ 2013-11-22,10,20
6
+ 2013-11-22,10,20,30
7
+ 2013-11-22,10,20,30
@@ -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
- display_url: 'http://test.com/',
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
- display_url: http://test.com/
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: '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
- display_url: 'http://test.com/',
14
- data: [["2013-11-20", "9.99470588235294", "11.003235294117646", "14.00164705882353"],
15
- ["2013-11-19", "10.039388096885814", nil, "14.09718770934256"]],
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.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-29 00:00:00.000000000 Z
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.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.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