quandl_data 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7b0f288b521778108286a02d72ff8fe057a0c4fe
4
- data.tar.gz: 2f0fcaf78040bcfd49bc3eabfa8351d9d6b7d0c4
3
+ metadata.gz: a671dc7961dc824080203af92205cbf45401c38c
4
+ data.tar.gz: 573b0ccfabfe0b929749f6b2d1d1ff40f10d22fa
5
5
  SHA512:
6
- metadata.gz: da18bc34e4157033a453de1ce35b1735e7ddfcfa81f46128517c2d63caab378d4d55a085dbac6b3cfcbba2ff9450a3ec820d4f26a07183fa49dda69cd27a59f3
7
- data.tar.gz: 1134498d2d40da8e57bcb0b14d9be9d19d0aeb35100e38e0d1a8aa074653670bf64a3470451f8cb58f1f90b832f33ec8423a0229ccb3ea60f09b6c84e5e11997
6
+ metadata.gz: 5e7dd6185d4c8947fffe2b450fd7c7d6ce217576c1a47e51a7f7cffa2b3c0712a75499f5f7fed0057bec51d71add108c841b3b801e4e756f2932e9ed86a42112
7
+ data.tar.gz: 2166730089b5375f8eba61a11db1108539bc3e9bf7f3f0c5299e6b8ee6f767675c2eabec9475f564e2a783bc12178e436d9477825dcf9390d20539f1ffd3152f
@@ -45,15 +45,15 @@ module Operations
45
45
  end
46
46
 
47
47
  def to_date!
48
- @data_array = to_date.to_a
48
+ @data_array = to_date.data_array
49
49
  self
50
50
  end
51
51
  def to_date
52
- Parse.julian_to_date data_array
52
+ Table.new( Parse.julian_to_date( data_array ) )
53
53
  end
54
54
 
55
55
  def trim_start!(trim_date)
56
- @data_array = trim_start(trim_date).to_a
56
+ @data_array = trim_start(trim_date).data_array
57
57
  self
58
58
  end
59
59
  def trim_start(trim_date)
@@ -63,14 +63,15 @@ module Operations
63
63
  # find index
64
64
  return self unless trim_date.is_a?(Integer)
65
65
  # reject rows with dates less than
66
- sort_descending.delete_if do |row|
66
+ data = sort_descending.delete_if do |row|
67
67
  row_date = row[0]
68
68
  row_date < trim_date
69
69
  end
70
+ Table.new(data)
70
71
  end
71
72
 
72
73
  def trim_end!(trim_date)
73
- @data_array = trim_end(trim_date).to_a
74
+ @data_array = trim_end(trim_date).data_array
74
75
  self
75
76
  end
76
77
  def trim_end(trim_date)
@@ -80,35 +81,39 @@ module Operations
80
81
  # find index
81
82
  return self unless trim_date.is_a?(Integer)
82
83
  # reject rows with dates less than
83
- sort_descending.delete_if do |row|
84
+ data = sort_descending.delete_if do |row|
84
85
  row_date = row[0]
85
86
  row_date > trim_date
86
87
  end
88
+ Table.new(data)
87
89
  end
88
90
 
89
- def limit(amount)
90
- @data_array = data_array[0..( amount.to_i - 1 )] if amount.present?
91
+ def limit!(amount)
92
+ @data_array = limit(amount).data_array
91
93
  self
92
94
  end
95
+ def limit(amount)
96
+ Table.new( data_array[0..( amount.to_i - 1 )] )
97
+ end
93
98
 
94
99
  def sort_order(dir)
95
100
  dir == :asc ? sort_ascending! : sort_descending!
96
101
  end
97
102
 
98
103
  def sort_ascending!
99
- @data_array = sort_ascending.to_a
104
+ @data_array = sort_ascending.data_array
100
105
  self
101
106
  end
102
107
  def sort_ascending
103
- Table.new( Parse.sort( data_array, :asc ), frequency: frequency )
108
+ Table.new( Parse.sort( data_array.dup, :asc ), frequency: frequency )
104
109
  end
105
110
 
106
111
  def sort_descending!
107
- @data_array = sort_descending.to_a
112
+ @data_array = sort_descending.data_array
108
113
  self
109
114
  end
110
115
  def sort_descending
111
- Table.new( Parse.sort( data_array, :desc ), frequency: frequency )
116
+ Table.new( Parse.sort( data_array.dup, :desc ), frequency: frequency )
112
117
  end
113
118
 
114
119
  def transform(*args)
@@ -1,5 +1,5 @@
1
1
  module Quandl
2
2
  module Data
3
- VERSION = "0.1.3"
3
+ VERSION = "0.1.4"
4
4
  end
5
5
  end
@@ -47,22 +47,62 @@ describe Quandl::Data::Table do
47
47
  subject.limit(2).count.should eq 2
48
48
  end
49
49
 
50
- it "should convert julian dates to dates" do
51
- subject.to_date.first.first.should be_a Date
50
+ describe "to_date" do
51
+
52
+ it "should convert julian dates to dates" do
53
+ subject.to_date.first.first.should be_a Date
54
+ end
55
+
52
56
  end
53
57
 
54
- it "should delete everything before trim_start" do
55
- data = Quandl::Data::Random.table( nils: false, rows: 10, columns: 1 ).sort_descending
56
- date = data[-2][0]
57
- data.trim_start(date).count.should eq 9
58
+ describe "trim_end" do
59
+
60
+ it "should delete everything after trim_end" do
61
+ data = Quandl::Data::Random.table( nils: false, rows: 10, columns: 1 ).sort_descending
62
+ date = data[1][0]
63
+ data.trim_end!(date)
64
+ data.data_array.should be_a Array
65
+ data.count.should eq 9
66
+ end
67
+
68
+ it "should be chainable" do
69
+ subject.trim_end(subject.first.first).trim_end(subject.last.first)
70
+ end
71
+
72
+ it "should not alter the original object" do
73
+ data = subject.trim_end(subject[2][0])
74
+ subject.count.should eq 4
75
+ end
76
+
77
+ it "should alter the original object" do
78
+ subject.trim_end!(subject[2][0])
79
+ subject.count.should eq 2
80
+ end
81
+
58
82
  end
59
83
 
60
- it "should delete everything after trim_end" do
61
- data = Quandl::Data::Random.table( nils: false, rows: 10, columns: 1 ).sort_descending
62
- date = data[1][0]
63
- data.trim_end!(date)
64
- data.data_array.should be_a Array
65
- data.count.should eq 9
84
+ describe "trim_start" do
85
+
86
+ it "should delete everything before trim_start" do
87
+ data = Quandl::Data::Random.table( nils: false, rows: 10, columns: 1 ).sort_descending
88
+ date = data[-2][0]
89
+ data.trim_start(date).count.should eq 9
90
+ end
91
+
92
+ it "should be chainable" do
93
+ subject.trim_start(subject.first.first).trim_end(subject.last.first)
94
+ end
95
+
96
+ it "should not alter the original object" do
97
+ data = subject.trim_start(subject[2][0])
98
+ subject.count.should eq 4
99
+ end
100
+
101
+ it "should alter the original object" do
102
+ subject.trim_start!(subject[-3][0])
103
+ subject.count.should eq 2
104
+ end
105
+
66
106
  end
67
107
 
68
108
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quandl_data
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Hilscher