quandl_client 2.1.2 → 2.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: fc1aa6dec90e010ea28015ad8d64597bd4f62740
4
- data.tar.gz: d7a7ab62d300cc027c55cc448299ec2b30df5bcf
3
+ metadata.gz: 157ba17ffc15b48c794cabd8eac6fc849345f125
4
+ data.tar.gz: 0d880279cca152565a9cc2b396328d49a02c8557
5
5
  SHA512:
6
- metadata.gz: e198ce8a28d9501a8e2b384aab223f888688bf35fcb5a13356254c4d9abf1fc405699d40e1eec555ad672880fe837f0b482736017f227aef10589251716b6caf
7
- data.tar.gz: 827642e483201531124d368852a2d473b760d715e2951404488facc5867bc713e6f023b83b5aacd39f1a549997b84623ee8a3afd6f8b16ebba9e6c820262081d
6
+ metadata.gz: dd2ba5539f6be665dcead9aafcc35cb5574379852061d7726e137a1ef8f35d16587a11d0fed704b67cd70f911be3a6e71c7370928600f7b40e4bbf1f6767a75a
7
+ data.tar.gz: 9eea7027c039f62c5bfc9850376b1c18c796a3f7cc5455e2b245d8ada84b769bbddbaa5578efb95771dde159f71770154311147e8e49f875f742ece70286e428
data/UPGRADE.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 2.1.3
2
+
3
+ * add specs for data scopes
4
+ * fix failing data scope specs
5
+
6
+
1
7
  ## 2.1.2
2
8
 
3
9
  * bump quandl_data, operation, logger
data/examples/client.rb CHANGED
@@ -3,10 +3,22 @@ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
3
3
  require 'pry'
4
4
  require "quandl/client"
5
5
  require "quandl/fabricate"
6
+ require 'securerandom'
6
7
 
7
8
  include Quandl::Client
8
9
 
9
10
  Quandl::Client.use 'http://quandl.com/api/'
10
- Quandl::Client.token = ENV['QUANDL_AUTH_TOKEN']
11
+ Quandl::Client.token = ENV['QUANDL_USER_TOKEN']
12
+
13
+ # create dataset
14
+ d = Dataset.new
15
+ d.code = "TEST_#{SecureRandom.hex[0..10]}".upcase
16
+ d.name = 'Blake Test Dataset'
17
+ d.save
18
+
19
+ # update dataset's data
20
+ new_data = Quandl::Fabricate::Data.rand( rows: 10, columns: 2, nils: false ).to_date.to_csv
21
+ d.data = new_data
22
+ d.save
11
23
 
12
24
  binding.pry
data/examples/trims.rb ADDED
@@ -0,0 +1,16 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
2
+
3
+ require 'pry'
4
+ require "quandl/client"
5
+
6
+ include Quandl::Client
7
+
8
+ Quandl::Client.use 'http://quandl.com/api/'
9
+ Quandl::Client.token = ENV['QUANDL_USER_TOKEN']
10
+
11
+ # create dataset
12
+ d = Dataset.find('NSE/OIL')
13
+
14
+ data = d.data.trim_start( 3.weeks.ago ).limit(10)
15
+
16
+ binding.pry
@@ -20,7 +20,7 @@ module Search
20
20
  scope_helper :connection, -> { self.class.parent }
21
21
 
22
22
  scope.class_eval do
23
-
23
+
24
24
  delegate *Array.forwardable_methods.reject{|m| [:find, :fetch].include?(m) }, to: :all
25
25
 
26
26
  def fetch_once
@@ -32,7 +32,9 @@ module Search
32
32
  end
33
33
 
34
34
  def find(id)
35
- result = self.class.parent.where(attributes).find(id)
35
+ attrs = attributes.merge(scope_attributes)
36
+ puts attrs
37
+ result = self.class.parent.where( attrs ).find(id)
36
38
  result = self.class.parent.new(id: id) if result.nil?
37
39
  result
38
40
  end
@@ -4,16 +4,32 @@ class Quandl::Client::Dataset::Data < Quandl::Client::Base
4
4
 
5
5
  has_scope_composer
6
6
 
7
- scope *[:row, :rows, :limit, :offset, :accuracy, :column, :order,
8
- :trim_start, :trim_end, :transform, :collapse, :exclude_headers]
9
-
10
- scope_helper :to_table, -> { fetch_once.data }
11
-
12
7
  scope.class_eval do
13
8
  delegate *Quandl::Client::Dataset::Data.forwardable_scope_methods, :to_h, to: :to_table, allow_nil: true
14
9
  delegate *Quandl::Data.forwardable_methods, to: :to_table, allow_nil: true
15
10
  end
16
-
11
+
12
+ scope *[:row, :rows, :limit, :offset, :accuracy, :column, :order,
13
+ :transform, :collapse, :exclude_headers]
14
+
15
+ scope :trim_start, ->(date){ date = parse_date(date); where( trim_start: date ) if date }
16
+ scope :trim_end, ->(date){ date = parse_date(date); where( trim_end: date ) if date }
17
+
18
+ scope_helper :parse_date, ->( value ){
19
+ begin
20
+ date = Date.jd(value.to_i) if value.kind_of?(String) && value.numeric?
21
+ date = Date.jd(value) if value.is_a?(Integer)
22
+ date = Date.parse(value) if value.is_a?(String) && value =~ /^[0-9]{4}\-[0-9]{2}\-[0-9]{2}$/
23
+ date = value if value.is_a?(Date)
24
+ date = value.to_date if value.respond_to?(:to_date)
25
+ date.to_s
26
+ rescue
27
+ nil
28
+ end
29
+ }
30
+
31
+ scope_helper :to_table, -> { fetch_once.data }
32
+
17
33
  attributes :id, :limit, :collapse, :transformation, :trim_start, :trim_end,
18
34
  :rows, :row, :frequency, :data, :from_date, :to_date
19
35
 
@@ -1,6 +1,6 @@
1
1
  module Quandl
2
2
  module Client
3
- VERSION = '2.1.2'
3
+ VERSION = '2.1.3'
4
4
  API_VERSION = 'v2'
5
5
 
6
6
  class << self
@@ -1,12 +1,30 @@
1
1
  # encoding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
- describe Dataset do
4
+ describe Quandl::Client::Dataset::Data do
5
5
 
6
6
  let(:dataset){
7
7
  create(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE", data: Quandl::Fabricate::Data.rand( rows: 10, columns: 4 ) )
8
8
  }
9
-
9
+
10
+ describe ".with_id" do
11
+ subject{ Quandl::Client::Dataset::Data.with_id(6668) }
12
+ let(:data){ Quandl::Client::Dataset::Data.with_id(6668).to_table }
13
+
14
+ let(:beginning_of_last_week){ Date.today.jd - Date.today.beginning_of_week.jd }
15
+
16
+ it("data"){ data.count.should > 100 }
17
+ it(".row(:beginning_of_last_week)"){ subject.row( beginning_of_last_week ).to_table.count.should eq 1 }
18
+ it(".rows(5)"){ subject.rows(5).to_table.count.should eq 5 }
19
+ it(".limit(2)"){ subject.limit(2).to_table.count.should eq 2 }
20
+ it(".column(2)"){ subject.column(2).to_table.first.count.should eq 2 }
21
+ it(".order('asc')"){ subject.order('asc').to_table.first.first.should eq data.sort_ascending!.first.first }
22
+ it(".order('desc')"){ subject.order('desc').to_table.first.first.should eq data.sort_descending!.first.first }
23
+ it(".trim_start().trim_end()"){ subject.trim_start( data[11].first ).trim_end(data[10].first).to_table.first.first.should eq data[10].first }
24
+ it(".collapse('monthly')"){ subject.collapse('monthly').to_table.frequency.should eq :monthly }
25
+ it(".transform('rdiff')"){ subject.transform('rdiff').to_table[0][1].should_not eq data[0][1] }
26
+ end
27
+
10
28
  describe "#data" do
11
29
  subject{ Dataset.find( dataset.id ).data }
12
30
  its(:count){ should eq 10 }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quandl_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.1.3
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-14 00:00:00.000000000 Z
11
+ date: 2013-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -181,6 +181,7 @@ files:
181
181
  - Rakefile
182
182
  - UPGRADE.md
183
183
  - examples/client.rb
184
+ - examples/trims.rb
184
185
  - lib/quandl/client.rb
185
186
  - lib/quandl/client/base.rb
186
187
  - lib/quandl/client/base/attributes.rb