quandl_client 2.7.3 → 2.7.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -6
- data/.rspec +1 -1
- data/.travis.yml +20 -20
- data/.yardopts +2 -2
- data/Gemfile +12 -12
- data/Guardfile +8 -8
- data/LICENSE +7 -7
- data/README.md +303 -303
- data/Rakefile +35 -35
- data/UPGRADE.md +210 -207
- data/VERSION +1 -1
- data/examples/create.rb +32 -32
- data/examples/find.rb +17 -17
- data/examples/login.rb +12 -12
- data/examples/search.rb +12 -12
- data/examples/trims.rb +15 -15
- data/lib/quandl/client.rb +49 -49
- data/lib/quandl/client/base.rb +91 -91
- data/lib/quandl/client/base/attributes.rb +15 -15
- data/lib/quandl/client/base/model.rb +40 -40
- data/lib/quandl/client/base/search.rb +74 -74
- data/lib/quandl/client/base/validation.rb +101 -101
- data/lib/quandl/client/middleware.rb +9 -9
- data/lib/quandl/client/middleware/parse_json.rb +85 -85
- data/lib/quandl/client/models/dataset.rb +245 -245
- data/lib/quandl/client/models/dataset/data.rb +57 -57
- data/lib/quandl/client/models/location.rb +10 -10
- data/lib/quandl/client/models/report.rb +14 -14
- data/lib/quandl/client/models/scraper.rb +16 -16
- data/lib/quandl/client/models/sheet.rb +50 -50
- data/lib/quandl/client/models/source.rb +40 -40
- data/lib/quandl/client/models/superset.rb +59 -59
- data/lib/quandl/client/models/user.rb +7 -7
- data/lib/quandl/client/version.rb +14 -14
- data/lib/quandl/her/remove_method_data.rb +8 -8
- data/lib/quandl/pattern.rb +37 -37
- data/lib/quandl/pattern/client.rb +8 -8
- data/quandl_client.gemspec +33 -33
- data/spec/factories/dataset.rb +10 -10
- data/spec/factories/sheet.rb +7 -7
- data/spec/factories/source.rb +9 -9
- data/spec/fixtures/scraper.rb +5 -5
- data/spec/lib/quandl/client/dataset/attributes_spec.rb +63 -63
- data/spec/lib/quandl/client/dataset/data_spec.rb +92 -92
- data/spec/lib/quandl/client/dataset/location_spec.rb +65 -65
- data/spec/lib/quandl/client/dataset/persistence_spec.rb +104 -104
- data/spec/lib/quandl/client/dataset/search_spec.rb +19 -19
- data/spec/lib/quandl/client/dataset/source_spec.rb +47 -47
- data/spec/lib/quandl/client/dataset/trim_spec.rb +35 -35
- data/spec/lib/quandl/client/dataset/validation_spec.rb +68 -68
- data/spec/lib/quandl/client/dataset_spec.rb +57 -57
- data/spec/lib/quandl/client/scraper_spec.rb +71 -71
- data/spec/lib/quandl/client/sheet_spec.rb +37 -37
- data/spec/lib/quandl/client/source_spec.rb +51 -51
- data/spec/spec_helper.rb +30 -30
- metadata +5 -27
@@ -1,8 +1,8 @@
|
|
1
|
-
class Quandl::Client::User < Quandl::Client::Base
|
2
|
-
|
3
|
-
custom_get :info
|
4
|
-
custom_post :login
|
5
|
-
|
6
|
-
attributes :auth_token
|
7
|
-
|
1
|
+
class Quandl::Client::User < Quandl::Client::Base
|
2
|
+
|
3
|
+
custom_get :info
|
4
|
+
custom_post :login
|
5
|
+
|
6
|
+
attributes :auth_token
|
7
|
+
|
8
8
|
end
|
@@ -1,15 +1,15 @@
|
|
1
|
-
module Quandl
|
2
|
-
module Client
|
3
|
-
VERSION = File.read(File.expand_path(File.join(File.dirname(__FILE__), '../../../VERSION'))).strip.rstrip
|
4
|
-
API_VERSION = 'v2'
|
5
|
-
|
6
|
-
class << self
|
7
|
-
|
8
|
-
def api_version
|
9
|
-
API_VERSION
|
10
|
-
end
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
1
|
+
module Quandl
|
2
|
+
module Client
|
3
|
+
VERSION = File.read(File.expand_path(File.join(File.dirname(__FILE__), '../../../VERSION'))).strip.rstrip
|
4
|
+
API_VERSION = 'v2'
|
5
|
+
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def api_version
|
9
|
+
API_VERSION
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
15
|
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
module Her
|
2
|
-
module Model
|
3
|
-
# remove deprecated data method since cassinatra returns data: []
|
4
|
-
module DeprecatedMethods
|
5
|
-
remove_method( :data ) if method_defined?( :data )
|
6
|
-
remove_method( :data= ) if method_defined?( :data= )
|
7
|
-
end
|
8
|
-
end
|
1
|
+
module Her
|
2
|
+
module Model
|
3
|
+
# remove deprecated data method since cassinatra returns data: []
|
4
|
+
module DeprecatedMethods
|
5
|
+
remove_method( :data ) if method_defined?( :data )
|
6
|
+
remove_method( :data= ) if method_defined?( :data= )
|
7
|
+
end
|
8
|
+
end
|
9
9
|
end
|
data/lib/quandl/pattern.rb
CHANGED
@@ -1,38 +1,38 @@
|
|
1
|
-
module Quandl
|
2
|
-
class Pattern < Regexp
|
3
|
-
|
4
|
-
class << self
|
5
|
-
|
6
|
-
def define_pattern(name, pattern, options={})
|
7
|
-
assert_unique_pattern!(name, pattern)
|
8
|
-
patterns << name
|
9
|
-
define_singleton_method(name){ Quandl::Pattern.new( pattern, options ) }
|
10
|
-
end
|
11
|
-
|
12
|
-
def assert_unique_pattern!(name, pattern)
|
13
|
-
return false unless self.respond_to?(name)
|
14
|
-
message = "Attempted to redefine previously defined pattern! '#{name}', /#{pattern}/"
|
15
|
-
raise ArgumentError.new(name), message
|
16
|
-
end
|
17
|
-
|
18
|
-
def patterns
|
19
|
-
@patterns ||= []
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
def initialize(*args)
|
25
|
-
@options = args.pop if args.last.is_a?(Hash)
|
26
|
-
super(*args)
|
27
|
-
end
|
28
|
-
|
29
|
-
def to_example
|
30
|
-
options[:example]
|
31
|
-
end
|
32
|
-
|
33
|
-
def options
|
34
|
-
@options ||= {}
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
1
|
+
module Quandl
|
2
|
+
class Pattern < Regexp
|
3
|
+
|
4
|
+
class << self
|
5
|
+
|
6
|
+
def define_pattern(name, pattern, options={})
|
7
|
+
assert_unique_pattern!(name, pattern)
|
8
|
+
patterns << name
|
9
|
+
define_singleton_method(name){ Quandl::Pattern.new( pattern, options ) }
|
10
|
+
end
|
11
|
+
|
12
|
+
def assert_unique_pattern!(name, pattern)
|
13
|
+
return false unless self.respond_to?(name)
|
14
|
+
message = "Attempted to redefine previously defined pattern! '#{name}', /#{pattern}/"
|
15
|
+
raise ArgumentError.new(name), message
|
16
|
+
end
|
17
|
+
|
18
|
+
def patterns
|
19
|
+
@patterns ||= []
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
def initialize(*args)
|
25
|
+
@options = args.pop if args.last.is_a?(Hash)
|
26
|
+
super(*args)
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_example
|
30
|
+
options[:example]
|
31
|
+
end
|
32
|
+
|
33
|
+
def options
|
34
|
+
@options ||= {}
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
38
|
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
module Quandl
|
2
|
-
class Pattern
|
3
|
-
|
4
|
-
define_pattern :dataset_date, /[0-9]{4}\-[0-9]{2}\-[0-9]{2}/, example: "yyyy-mm-dd"
|
5
|
-
define_pattern :code, /[A-Z0-9_]+/, example: 'ALPHA_NUMERIC_ALL_CAPS'
|
6
|
-
define_pattern :full_code, /(#{code}+)\/?(#{code})?/, example: "(SOURCE_CODE/)#{code.to_example}"
|
7
|
-
|
8
|
-
end
|
1
|
+
module Quandl
|
2
|
+
class Pattern
|
3
|
+
|
4
|
+
define_pattern :dataset_date, /[0-9]{4}\-[0-9]{2}\-[0-9]{2}/, example: "yyyy-mm-dd"
|
5
|
+
define_pattern :code, /[A-Z0-9_]+/, example: 'ALPHA_NUMERIC_ALL_CAPS'
|
6
|
+
define_pattern :full_code, /(#{code}+)\/?(#{code})?/, example: "(SOURCE_CODE/)#{code.to_example}"
|
7
|
+
|
8
|
+
end
|
9
9
|
end
|
data/quandl_client.gemspec
CHANGED
@@ -1,34 +1,34 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "quandl/client/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |s|
|
6
|
-
s.name = "quandl_client"
|
7
|
-
s.version = Quandl::Client::VERSION
|
8
|
-
s.authors = ["Blake Hilscher"]
|
9
|
-
s.email = ["blake@hilscher.ca"]
|
10
|
-
s.homepage = "http://blake.hilscher.ca/"
|
11
|
-
s.license = "MIT"
|
12
|
-
s.summary = "Client rest orm."
|
13
|
-
s.description = "An orm for the cassinatra rest interface."
|
14
|
-
|
15
|
-
s.files = `git ls-files`.split("\n")
|
16
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
-
s.require_paths = ["lib"]
|
19
|
-
|
20
|
-
s.add_runtime_dependency "quandl_data", "~> 1.4"
|
21
|
-
s.add_runtime_dependency "activesupport", ">= 3.0.0"
|
22
|
-
s.add_runtime_dependency "her", "~> 0.6"
|
23
|
-
s.add_runtime_dependency 'json', '~> 1.7.7'
|
24
|
-
s.add_runtime_dependency "scope_composer", "~> 0.3"
|
25
|
-
|
26
|
-
s.add_development_dependency "rake", "~> 10.0"
|
27
|
-
s.add_development_dependency "rspec", "~> 2.13"
|
28
|
-
s.add_development_dependency "factory_girl_rails"
|
29
|
-
s.add_development_dependency "fivemat", "~> 1.2"
|
30
|
-
s.add_development_dependency "pry"
|
31
|
-
s.add_development_dependency "guard"
|
32
|
-
s.add_development_dependency "guard-rspec"
|
33
|
-
s.add_development_dependency "quandl_utility"
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "quandl/client/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "quandl_client"
|
7
|
+
s.version = Quandl::Client::VERSION
|
8
|
+
s.authors = ["Blake Hilscher"]
|
9
|
+
s.email = ["blake@hilscher.ca"]
|
10
|
+
s.homepage = "http://blake.hilscher.ca/"
|
11
|
+
s.license = "MIT"
|
12
|
+
s.summary = "Client rest orm."
|
13
|
+
s.description = "An orm for the cassinatra rest interface."
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.add_runtime_dependency "quandl_data", "~> 1.4"
|
21
|
+
s.add_runtime_dependency "activesupport", ">= 3.0.0"
|
22
|
+
s.add_runtime_dependency "her", "~> 0.6"
|
23
|
+
s.add_runtime_dependency 'json', '~> 1.7.7'
|
24
|
+
s.add_runtime_dependency "scope_composer", "~> 0.3"
|
25
|
+
|
26
|
+
s.add_development_dependency "rake", "~> 10.0"
|
27
|
+
s.add_development_dependency "rspec", "~> 2.13"
|
28
|
+
s.add_development_dependency "factory_girl_rails"
|
29
|
+
s.add_development_dependency "fivemat", "~> 1.2"
|
30
|
+
s.add_development_dependency "pry"
|
31
|
+
s.add_development_dependency "guard"
|
32
|
+
s.add_development_dependency "guard-rspec"
|
33
|
+
s.add_development_dependency "quandl_utility"
|
34
34
|
end
|
data/spec/factories/dataset.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
FactoryGirl.define do
|
2
|
-
|
3
|
-
factory :dataset do
|
4
|
-
source_code "QUANDL_CLIENT_TEST_SOURCE"
|
5
|
-
sequence(:code) { |n| "QUANDL_CLIENT_#{(Time.now.to_f * 1000).to_i}_#{n}" }
|
6
|
-
name "Quandl Client Dataset"
|
7
|
-
description "Quandl Client Dataset Spec"
|
8
|
-
# column_names ['Date', "Column 1", "Column 2"]
|
9
|
-
end
|
10
|
-
|
1
|
+
FactoryGirl.define do
|
2
|
+
|
3
|
+
factory :dataset do
|
4
|
+
source_code "QUANDL_CLIENT_TEST_SOURCE"
|
5
|
+
sequence(:code) { |n| "QUANDL_CLIENT_#{(Time.now.to_f * 1000).to_i}_#{n}" }
|
6
|
+
name "Quandl Client Dataset"
|
7
|
+
description "Quandl Client Dataset Spec"
|
8
|
+
# column_names ['Date', "Column 1", "Column 2"]
|
9
|
+
end
|
10
|
+
|
11
11
|
end
|
data/spec/factories/sheet.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
FactoryGirl.define do
|
2
|
-
|
3
|
-
factory :sheet do
|
4
|
-
sequence(:title) { |n| "Test sheet #{n} #{(Time.now.to_f * 1000).to_i}" }
|
5
|
-
description{ "Test sheet description."}
|
6
|
-
end
|
7
|
-
|
1
|
+
FactoryGirl.define do
|
2
|
+
|
3
|
+
factory :sheet do
|
4
|
+
sequence(:title) { |n| "Test sheet #{n} #{(Time.now.to_f * 1000).to_i}" }
|
5
|
+
description{ "Test sheet description."}
|
6
|
+
end
|
7
|
+
|
8
8
|
end
|
data/spec/factories/source.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
FactoryGirl.define do
|
2
|
-
|
3
|
-
factory :source do
|
4
|
-
sequence(:code) { |n| "QUANDL_CLIENT_#{(Time.now.to_f * 1000).to_i}_#{n}" }
|
5
|
-
name "Quandl Client Source"
|
6
|
-
description "Quandl Client Source Spec"
|
7
|
-
sequence(:host) { |n| "http://quandl.com/host/#{(Time.now.to_f * 1000).to_i}_#{n}" }
|
8
|
-
end
|
9
|
-
|
1
|
+
FactoryGirl.define do
|
2
|
+
|
3
|
+
factory :source do
|
4
|
+
sequence(:code) { |n| "QUANDL_CLIENT_#{(Time.now.to_f * 1000).to_i}_#{n}" }
|
5
|
+
name "Quandl Client Source"
|
6
|
+
description "Quandl Client Source Spec"
|
7
|
+
sequence(:host) { |n| "http://quandl.com/host/#{(Time.now.to_f * 1000).to_i}_#{n}" }
|
8
|
+
end
|
9
|
+
|
10
10
|
end
|
data/spec/fixtures/scraper.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
puts %Q{
|
2
|
-
code: SCRAPE_SOME_DATA
|
3
|
-
-
|
4
|
-
Date,Value
|
5
|
-
#{Time.now.strftime("%Y-%m-%d")},10
|
1
|
+
puts %Q{
|
2
|
+
code: SCRAPE_SOME_DATA
|
3
|
+
-
|
4
|
+
Date,Value
|
5
|
+
#{Time.now.strftime("%Y-%m-%d")},10
|
6
6
|
}
|
@@ -1,64 +1,64 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe Dataset do
|
5
|
-
|
6
|
-
let(:source){
|
7
|
-
s = Source.find("QUANDL_CLIENT_TEST_SOURCE")
|
8
|
-
s = create(:source, code: "QUANDL_CLIENT_TEST_SOURCE") unless s.exists?
|
9
|
-
s
|
10
|
-
}
|
11
|
-
subject{ create(:dataset, source_code: source.code, private: true ) }
|
12
|
-
|
13
|
-
describe "#code" do
|
14
|
-
subject{ build(:dataset, source_code: source.code.downcase ) }
|
15
|
-
before(:each){}
|
16
|
-
it "lowercase code should be valid" do
|
17
|
-
subject.code = subject.code.downcase
|
18
|
-
subject.save
|
19
|
-
subject.saved?.should be_true
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "#name" do
|
25
|
-
subject{ create(:dataset, source_code: source.code, private: true, name: '' ) }
|
26
|
-
|
27
|
-
its(:name){ should match /Untitled Dataset #{Date.today}/ }
|
28
|
-
end
|
29
|
-
|
30
|
-
describe "#reference_url" do
|
31
|
-
let(:url){ "http://website.com/path/to/reference" }
|
32
|
-
let(:dataset){ Dataset.new( reference_url: url, code: "VALID" ) }
|
33
|
-
subject{ dataset }
|
34
|
-
|
35
|
-
its(:reference_url){ should eq url }
|
36
|
-
its(:valid?){ should be_true }
|
37
|
-
|
38
|
-
context "partial url" do
|
39
|
-
let(:url){ "website.com/path/to/reference" }
|
40
|
-
its(:reference_url){ should eq "http://website.com/path/to/reference" }
|
41
|
-
its(:valid?){ should be_true }
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
describe "#private" do
|
47
|
-
|
48
|
-
it "should update to false" do
|
49
|
-
subject.private = false
|
50
|
-
subject.save
|
51
|
-
Dataset.find(subject.id).private.should be_false
|
52
|
-
end
|
53
|
-
|
54
|
-
it "should update to true" do
|
55
|
-
subject.private = false
|
56
|
-
subject.save
|
57
|
-
subject.private = true
|
58
|
-
subject.save
|
59
|
-
Dataset.find(subject.id).private.should be_true
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
63
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Dataset do
|
5
|
+
|
6
|
+
let(:source){
|
7
|
+
s = Source.find("QUANDL_CLIENT_TEST_SOURCE")
|
8
|
+
s = create(:source, code: "QUANDL_CLIENT_TEST_SOURCE") unless s.exists?
|
9
|
+
s
|
10
|
+
}
|
11
|
+
subject{ create(:dataset, source_code: source.code, private: true ) }
|
12
|
+
|
13
|
+
describe "#code" do
|
14
|
+
subject{ build(:dataset, source_code: source.code.downcase ) }
|
15
|
+
before(:each){}
|
16
|
+
it "lowercase code should be valid" do
|
17
|
+
subject.code = subject.code.downcase
|
18
|
+
subject.save
|
19
|
+
subject.saved?.should be_true
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#name" do
|
25
|
+
subject{ create(:dataset, source_code: source.code, private: true, name: '' ) }
|
26
|
+
|
27
|
+
its(:name){ should match /Untitled Dataset #{Date.today}/ }
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#reference_url" do
|
31
|
+
let(:url){ "http://website.com/path/to/reference" }
|
32
|
+
let(:dataset){ Dataset.new( reference_url: url, code: "VALID" ) }
|
33
|
+
subject{ dataset }
|
34
|
+
|
35
|
+
its(:reference_url){ should eq url }
|
36
|
+
its(:valid?){ should be_true }
|
37
|
+
|
38
|
+
context "partial url" do
|
39
|
+
let(:url){ "website.com/path/to/reference" }
|
40
|
+
its(:reference_url){ should eq "http://website.com/path/to/reference" }
|
41
|
+
its(:valid?){ should be_true }
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#private" do
|
47
|
+
|
48
|
+
it "should update to false" do
|
49
|
+
subject.private = false
|
50
|
+
subject.save
|
51
|
+
Dataset.find(subject.id).private.should be_false
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should update to true" do
|
55
|
+
subject.private = false
|
56
|
+
subject.save
|
57
|
+
subject.private = true
|
58
|
+
subject.save
|
59
|
+
Dataset.find(subject.id).private.should be_true
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
64
|
end
|
@@ -1,93 +1,93 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe Quandl::Client::Dataset::Data do
|
5
|
-
|
6
|
-
let(:dataset){
|
7
|
-
create(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE", data: Quandl::Fabricate::Data.rand( rows: 10, columns: 4 ), column_names: ["Date", "C1", 'c2', 'c3', 'c4'] )
|
8
|
-
}
|
9
|
-
subject{ dataset }
|
10
|
-
|
11
|
-
its(:valid?){ should be_true }
|
12
|
-
|
13
|
-
describe ".with_id('NSE/OIL')" do
|
14
|
-
let(:id){ Dataset.find("NSE/OIL").id }
|
15
|
-
subject{ Quandl::Client::Dataset::Data.with_id(id) }
|
16
|
-
let(:data){ Quandl::Client::Dataset::Data.with_id(id).to_table }
|
17
|
-
|
18
|
-
let(:beginning_of_last_week){ Date.today.jd - Date.today.beginning_of_week.jd }
|
19
|
-
|
20
|
-
it("data"){ data.count.should > 100 }
|
21
|
-
it(".rows(5)"){ subject.rows(5).to_table.count.should eq 5 }
|
22
|
-
it(".limit(2)"){ subject.limit(2).to_table.count.should eq 2 }
|
23
|
-
it(".column(2)"){ subject.column(2).to_table.first.count.should eq 2 }
|
24
|
-
it(".order('asc')"){ subject.order('asc').to_table.first.first.should eq data.sort_ascending!.first.first }
|
25
|
-
it(".order('desc')"){ subject.order('desc').to_table.first.first.should eq data.sort_descending!.first.first }
|
26
|
-
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 }
|
27
|
-
it(".collapse('monthly')"){ subject.collapse('monthly').to_table.frequency.should eq :monthly }
|
28
|
-
it(".transform('rdiff')"){ subject.transform('rdiff').to_table[0][1].should_not eq data[0][1] }
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "#data" do
|
32
|
-
subject{ Dataset.find( dataset.id ).data }
|
33
|
-
|
34
|
-
its(:count){ should eq 10 }
|
35
|
-
its(:to_h){ should be_a Hash }
|
36
|
-
end
|
37
|
-
|
38
|
-
context "updated" do
|
39
|
-
|
40
|
-
subject{
|
41
|
-
dataset.updated_at
|
42
|
-
sleep(0.75)
|
43
|
-
Dataset.find( dataset.id )
|
44
|
-
}
|
45
|
-
|
46
|
-
describe "#data" do
|
47
|
-
before(:each){ subject.data = Quandl::Fabricate::Data.rand( rows: 12, columns: 4 ); sleep(1); subject.save }
|
48
|
-
its(:updated_at){ should_not eq dataset.updated_at }
|
49
|
-
its(:data){ should_not eq dataset.data }
|
50
|
-
its(:refreshed_at){ should_not eq dataset.refreshed_at }
|
51
|
-
end
|
52
|
-
|
53
|
-
context "#column_spec" do
|
54
|
-
before(:each){ subject.column_spec = "[0,[\"Date\",{}],[\"c1 \",{}],[\"c2 \",{}],[\"c3 \",{}],[\"c234 \",{}]]"; sleep(1); subject.save }
|
55
|
-
its(:updated_at){ should_not eq dataset.updated_at }
|
56
|
-
its(:column_spec){ should_not eq dataset.column_spec }
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
|
61
|
-
describe "#delete_data" do
|
62
|
-
subject{ Dataset.find( dataset.id ) }
|
63
|
-
before(:each){ subject.delete_data }
|
64
|
-
its(:data){ should be_blank }
|
65
|
-
end
|
66
|
-
|
67
|
-
describe "#delete_rows" do
|
68
|
-
subject{ Dataset.find( dataset.id ) }
|
69
|
-
|
70
|
-
let(:dates_slice){ dataset.data.to_date.to_h.keys[5..8] }
|
71
|
-
|
72
|
-
it "should have the dates" do
|
73
|
-
dates = Dataset.find( dataset.id ).data.to_date.to_h.keys
|
74
|
-
dates_slice.each{|date| dates.include?(date).should be_true }
|
75
|
-
end
|
76
|
-
|
77
|
-
context "after deleting rows" do
|
78
|
-
|
79
|
-
before(:each){ subject.delete_rows(dates_slice) }
|
80
|
-
|
81
|
-
it "data count should be 6" do
|
82
|
-
Dataset.find( dataset.id ).data.count.should eq 6
|
83
|
-
end
|
84
|
-
|
85
|
-
it "data should have dates" do
|
86
|
-
dates = Dataset.find( dataset.id ).data.to_h
|
87
|
-
dates.each{|date| dates_slice.include?(date).should be_false }
|
88
|
-
end
|
89
|
-
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Quandl::Client::Dataset::Data do
|
5
|
+
|
6
|
+
let(:dataset){
|
7
|
+
create(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE", data: Quandl::Fabricate::Data.rand( rows: 10, columns: 4 ), column_names: ["Date", "C1", 'c2', 'c3', 'c4'] )
|
8
|
+
}
|
9
|
+
subject{ dataset }
|
10
|
+
|
11
|
+
its(:valid?){ should be_true }
|
12
|
+
|
13
|
+
describe ".with_id('NSE/OIL')" do
|
14
|
+
let(:id){ Dataset.find("NSE/OIL").id }
|
15
|
+
subject{ Quandl::Client::Dataset::Data.with_id(id) }
|
16
|
+
let(:data){ Quandl::Client::Dataset::Data.with_id(id).to_table }
|
17
|
+
|
18
|
+
let(:beginning_of_last_week){ Date.today.jd - Date.today.beginning_of_week.jd }
|
19
|
+
|
20
|
+
it("data"){ data.count.should > 100 }
|
21
|
+
it(".rows(5)"){ subject.rows(5).to_table.count.should eq 5 }
|
22
|
+
it(".limit(2)"){ subject.limit(2).to_table.count.should eq 2 }
|
23
|
+
it(".column(2)"){ subject.column(2).to_table.first.count.should eq 2 }
|
24
|
+
it(".order('asc')"){ subject.order('asc').to_table.first.first.should eq data.sort_ascending!.first.first }
|
25
|
+
it(".order('desc')"){ subject.order('desc').to_table.first.first.should eq data.sort_descending!.first.first }
|
26
|
+
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 }
|
27
|
+
it(".collapse('monthly')"){ subject.collapse('monthly').to_table.frequency.should eq :monthly }
|
28
|
+
it(".transform('rdiff')"){ subject.transform('rdiff').to_table[0][1].should_not eq data[0][1] }
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#data" do
|
32
|
+
subject{ Dataset.find( dataset.id ).data }
|
33
|
+
|
34
|
+
its(:count){ should eq 10 }
|
35
|
+
its(:to_h){ should be_a Hash }
|
36
|
+
end
|
37
|
+
|
38
|
+
context "updated" do
|
39
|
+
|
40
|
+
subject{
|
41
|
+
dataset.updated_at
|
42
|
+
sleep(0.75)
|
43
|
+
Dataset.find( dataset.id )
|
44
|
+
}
|
45
|
+
|
46
|
+
describe "#data" do
|
47
|
+
before(:each){ subject.data = Quandl::Fabricate::Data.rand( rows: 12, columns: 4 ); sleep(1); subject.save }
|
48
|
+
its(:updated_at){ should_not eq dataset.updated_at }
|
49
|
+
its(:data){ should_not eq dataset.data }
|
50
|
+
its(:refreshed_at){ should_not eq dataset.refreshed_at }
|
51
|
+
end
|
52
|
+
|
53
|
+
context "#column_spec" do
|
54
|
+
before(:each){ subject.column_spec = "[0,[\"Date\",{}],[\"c1 \",{}],[\"c2 \",{}],[\"c3 \",{}],[\"c234 \",{}]]"; sleep(1); subject.save }
|
55
|
+
its(:updated_at){ should_not eq dataset.updated_at }
|
56
|
+
its(:column_spec){ should_not eq dataset.column_spec }
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "#delete_data" do
|
62
|
+
subject{ Dataset.find( dataset.id ) }
|
63
|
+
before(:each){ subject.delete_data }
|
64
|
+
its(:data){ should be_blank }
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "#delete_rows" do
|
68
|
+
subject{ Dataset.find( dataset.id ) }
|
69
|
+
|
70
|
+
let(:dates_slice){ dataset.data.to_date.to_h.keys[5..8] }
|
71
|
+
|
72
|
+
it "should have the dates" do
|
73
|
+
dates = Dataset.find( dataset.id ).data.to_date.to_h.keys
|
74
|
+
dates_slice.each{|date| dates.include?(date).should be_true }
|
75
|
+
end
|
76
|
+
|
77
|
+
context "after deleting rows" do
|
78
|
+
|
79
|
+
before(:each){ subject.delete_rows(dates_slice) }
|
80
|
+
|
81
|
+
it "data count should be 6" do
|
82
|
+
Dataset.find( dataset.id ).data.count.should eq 6
|
83
|
+
end
|
84
|
+
|
85
|
+
it "data should have dates" do
|
86
|
+
dates = Dataset.find( dataset.id ).data.to_h
|
87
|
+
dates.each{|date| dates_slice.include?(date).should be_false }
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
93
|
end
|