quandl_operation 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f793e84f6b1444296a2139214ac181e0a3175db5
4
- data.tar.gz: 1e07e11fac0532a64bb51a61227b76d33ba20ff6
3
+ metadata.gz: 8bc77362c57fff96b7d468ed11ecf3ced455cbcc
4
+ data.tar.gz: d63f23908949e9bd62b909772167c0569d146e66
5
5
  SHA512:
6
- metadata.gz: 72f3392d5646b4fac36ac7d83b11c0d53481b1bb4ed12c237b40c7acdb554f35450e9376ff6000fa3cb80fe3dd3c52116011301090bdf4dc7c2273ba0e5ab341
7
- data.tar.gz: 8bd50d06f6f8b57789694840594b9ff34e3326052cb05d4bc2f881e302c8432819d587e78217c85ade3866f34d417e14e6786a8c3bf2f98744e659bb342399f3
6
+ metadata.gz: d865104a72d0e0f9b01805489adbdd9ba1c96415e668191ce403c85e3766d497abd5276ade91eb504433f5e3f28e6757aa89f78010d6d397e3602ab5ebfea858
7
+ data.tar.gz: 5679b97f828bad24bdf8b53db30d01f6be47cb88f5429aba204d752c1d47e5b7d47f97e7b875d9128fe53da1ef217c1b4e7ac01afae7618a8879bec2171541d2
data/UPGRADE.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.2.1
2
+
3
+ * assert valid arguments for collapse and transform
4
+ * fix parse_date_string jd
5
+
6
+
1
7
  ## 0.2.0
2
8
 
3
9
  * rename Parse methods to be more informative
@@ -8,22 +8,29 @@ class Collapse
8
8
 
9
9
  class << self
10
10
 
11
- def perform(data, frequency)
12
- return data unless data.is_a?(Array) && data.compact.present?
13
- # source order
14
- order = Parse.sort_order?(data)
11
+ def perform(data, type)
12
+ assert_valid_arguments!(data, type)
13
+ # nothing to do with an empty array
14
+ return data unless data.compact.present?
15
15
  # ensure data is in expected format
16
16
  data = Parse.to_jd(data)
17
+ # source order
18
+ order = Parse.sort_order?(data)
17
19
  # operations expect data in ascending order
18
20
  data = Parse.sort( data, :asc )
19
21
  # collapse
20
- data = collapse(data, frequency)
22
+ data = collapse(data, type)
21
23
  # return to original order
22
24
  data = Parse.sort( data, :desc ) if order == :desc
23
25
  # onwards
24
26
  data
25
27
  end
26
28
 
29
+ def assert_valid_arguments!(data, type)
30
+ raise ArgumentError, "data must be an Array. Received: #{data.class}" unless data.is_a?(Array)
31
+ raise ArgumentError, "frequency must be one of #{valid_collapses}. Received: #{type}" unless valid?(type)
32
+ end
33
+
27
34
  def valid_collapse?(type)
28
35
  valid?(type)
29
36
  end
@@ -133,7 +133,9 @@ class Parse
133
133
  # otherwise cast string jds to int
134
134
  output = []
135
135
  data.each_with_index do |row, index|
136
- output << parse_date_string(row).jd rescue raise_date_format_error!( row, index, :date_strings_to_jd )
136
+ row = parse_date_string(row) rescue raise_date_format_error!( row, index, :date_strings_to_jd )
137
+ row[0] = row[0].jd
138
+ output << row
137
139
  end
138
140
  output
139
141
  end
@@ -6,7 +6,9 @@ class Transform
6
6
  class << self
7
7
 
8
8
  def perform( data, type )
9
- return data unless data.is_a?(Array) && data.compact.present?
9
+ assert_valid_arguments!(data, type)
10
+ # nothing to do with an empty array
11
+ return data unless data.compact.present?
10
12
  # original order
11
13
  order = Parse.sort_order?(data)
12
14
  # operations expect data in ascending order
@@ -21,6 +23,11 @@ class Transform
21
23
  data
22
24
  end
23
25
 
26
+ def assert_valid_arguments!(data, type)
27
+ raise ArgumentError, "data must be an Array. Received: #{data.class}" unless data.is_a?(Array)
28
+ raise ArgumentError, "frequency must be one of #{valid_transformations}. Received: #{type}" unless valid?(type)
29
+ end
30
+
24
31
  def valid_transformation?(type)
25
32
  valid?(type)
26
33
  end
@@ -1,5 +1,5 @@
1
1
  module Quandl
2
2
  module Operation
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
@@ -46,10 +46,10 @@ describe Quandl::Operation::Collapse do
46
46
  describe ".perform" do
47
47
 
48
48
  let(:data){
49
- [[2456537, 56.2, nil, nil],
49
+ Quandl::Operation::Parse.to_date([[2456537, 56.2, nil, nil],
50
50
  [2456518, 55.7, nil, nil], [2456506, nil, 136133.0, nil],
51
51
  [2456487, 55.4, nil, nil], [2456475, nil, 135964.0, nil],
52
- [2456457, 50.9, nil, nil], [2456445, nil, 135860.0, nil]]
52
+ [2456457, 50.9, nil, nil], [2456445, nil, 135860.0, nil]])
53
53
  }
54
54
 
55
55
  it "should collapse data with nils" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quandl_operation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Hilscher