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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 66cac1ad0db0943543233552e5b6d3b81cabf7fe
4
- data.tar.gz: 62fe7fc23777141e8625e620afb2e22c96014709
3
+ metadata.gz: 7b0f288b521778108286a02d72ff8fe057a0c4fe
4
+ data.tar.gz: 2f0fcaf78040bcfd49bc3eabfa8351d9d6b7d0c4
5
5
  SHA512:
6
- metadata.gz: 7453e322586fb29caaf1405f483095b6c24ef79c79fbc0d22158875d840c9a55eafd9f07a792a199ce8af7f15be226c591fdaaee6bc05d6599ade7cbbef9bdd3
7
- data.tar.gz: 1dc0ea26bfad0e1a3ee8a59535bd10c32e55a0747df17549841565c2503f271bfeaf6be3933ab7389feaced651414a69b0b5ab3582539580f839b8816cc66013
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
- def to_date!
51
- @data_array = Parse.julian_to_date data_array
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
- date = Date.parse(date) if date.is_a?(String)
58
- date = date.jd if date.respond_to?(:jd)
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
- index = data_array.rindex{|r| r[0] == date }
61
- # trim if index is valid
62
- @data_array = @data_array[index..-1] if index && @data_array[index]
63
- # chainable
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
- date = Date.parse(date) if date.is_a?(String)
70
- date = date.jd if date.respond_to?(:jd)
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
- index = data_array.rindex{|r| r[0] == date }
73
- # trim if index is valid
74
- @data_array = @data_array[0..index] if index && @data_array[index]
75
- # chainable
76
- self
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
- def sort_ascending!
92
- @data_array = Parse.sort( data_array, :asc )
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?
@@ -1,5 +1,5 @@
1
1
  module Quandl
2
2
  module Data
3
- VERSION = "0.1.2"
3
+ VERSION = "0.1.3"
4
4
  end
5
5
  end
@@ -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
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.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Hilscher