quandl_data 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/quandl/data/table/operations.rb +37 -27
- data/lib/quandl/data/version.rb +1 -1
- data/spec/quandl/data_spec.rb +14 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b0f288b521778108286a02d72ff8fe057a0c4fe
|
4
|
+
data.tar.gz: 2f0fcaf78040bcfd49bc3eabfa8351d9d6b7d0c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da18bc34e4157033a453de1ce35b1735e7ddfcfa81f46128517c2d63caab378d4d55a085dbac6b3cfcbba2ff9450a3ec820d4f26a07183fa49dda69cd27a59f3
|
7
|
+
data.tar.gz: 1134498d2d40da8e57bcb0b14d9be9d19d0aeb35100e38e0d1a8aa074653670bf64a3470451f8cb58f1f90b832f33ec8423a0229ccb3ea60f09b6c84e5e11997
|
@@ -43,37 +43,47 @@ module Operations
|
|
43
43
|
@data_array = Parse.date_to_julian( data_array )
|
44
44
|
self
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
|
+
def to_date!
|
48
|
+
@data_array = to_date.to_a
|
49
|
+
self
|
50
|
+
end
|
47
51
|
def to_date
|
48
52
|
Parse.julian_to_date data_array
|
49
53
|
end
|
50
|
-
|
51
|
-
|
54
|
+
|
55
|
+
def trim_start!(trim_date)
|
56
|
+
@data_array = trim_start(trim_date).to_a
|
52
57
|
self
|
53
58
|
end
|
54
|
-
|
55
|
-
def trim_start(date)
|
59
|
+
def trim_start(trim_date)
|
56
60
|
# date format
|
57
|
-
|
58
|
-
|
61
|
+
trim_date = Date.parse(trim_date) if trim_date.is_a?(String)
|
62
|
+
trim_date = trim_date.jd if trim_date.respond_to?(:jd)
|
59
63
|
# find index
|
60
|
-
|
61
|
-
#
|
62
|
-
|
63
|
-
|
64
|
+
return self unless trim_date.is_a?(Integer)
|
65
|
+
# reject rows with dates less than
|
66
|
+
sort_descending.delete_if do |row|
|
67
|
+
row_date = row[0]
|
68
|
+
row_date < trim_date
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def trim_end!(trim_date)
|
73
|
+
@data_array = trim_end(trim_date).to_a
|
64
74
|
self
|
65
75
|
end
|
66
|
-
|
67
|
-
def trim_end(date)
|
76
|
+
def trim_end(trim_date)
|
68
77
|
# date format
|
69
|
-
|
70
|
-
|
78
|
+
trim_date = Date.parse(trim_date) if trim_date.is_a?(String)
|
79
|
+
trim_date = trim_date.jd if trim_date.respond_to?(:jd)
|
71
80
|
# find index
|
72
|
-
|
73
|
-
#
|
74
|
-
|
75
|
-
|
76
|
-
|
81
|
+
return self unless trim_date.is_a?(Integer)
|
82
|
+
# reject rows with dates less than
|
83
|
+
sort_descending.delete_if do |row|
|
84
|
+
row_date = row[0]
|
85
|
+
row_date > trim_date
|
86
|
+
end
|
77
87
|
end
|
78
88
|
|
79
89
|
def limit(amount)
|
@@ -85,21 +95,21 @@ module Operations
|
|
85
95
|
dir == :asc ? sort_ascending! : sort_descending!
|
86
96
|
end
|
87
97
|
|
98
|
+
def sort_ascending!
|
99
|
+
@data_array = sort_ascending.to_a
|
100
|
+
self
|
101
|
+
end
|
88
102
|
def sort_ascending
|
89
103
|
Table.new( Parse.sort( data_array, :asc ), frequency: frequency )
|
90
104
|
end
|
91
|
-
|
92
|
-
|
105
|
+
|
106
|
+
def sort_descending!
|
107
|
+
@data_array = sort_descending.to_a
|
93
108
|
self
|
94
109
|
end
|
95
|
-
|
96
110
|
def sort_descending
|
97
111
|
Table.new( Parse.sort( data_array, :desc ), frequency: frequency )
|
98
112
|
end
|
99
|
-
def sort_descending!
|
100
|
-
@data_array = Parse.sort( data_array, :desc )
|
101
|
-
self
|
102
|
-
end
|
103
113
|
|
104
114
|
def transform(*args)
|
105
115
|
return @transform unless args.first.present?
|
data/lib/quandl/data/version.rb
CHANGED
data/spec/quandl/data_spec.rb
CHANGED
@@ -51,4 +51,18 @@ describe Quandl::Data::Table do
|
|
51
51
|
subject.to_date.first.first.should be_a Date
|
52
52
|
end
|
53
53
|
|
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
|
+
end
|
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
|
+
|
54
68
|
end
|