quandl_client 2.7.11 → 2.7.12
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -7
- 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 +31 -31
- data/UPGRADE.md +220 -214
- 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/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 +103 -101
- data/lib/quandl/client/base.rb +91 -91
- data/lib/quandl/client/middleware/parse_json.rb +87 -85
- data/lib/quandl/client/middleware.rb +9 -9
- data/lib/quandl/client/models/dataset/data.rb +57 -57
- data/lib/quandl/client/models/dataset.rb +269 -269
- 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 +48 -48
- data/lib/quandl/client/models/superset.rb +65 -65
- data/lib/quandl/client/models/user.rb +7 -7
- data/lib/quandl/client/version.rb +14 -14
- data/lib/quandl/client.rb +54 -53
- data/lib/quandl/her/collection.rb +18 -0
- data/lib/quandl/her/remove_method_data.rb +8 -8
- data/lib/quandl/pattern/client.rb +8 -8
- data/lib/quandl/pattern.rb +37 -37
- 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 +28 -4
@@ -1,51 +1,51 @@
|
|
1
|
-
module Quandl
|
2
|
-
module Client
|
3
|
-
|
4
|
-
class Sheet < Quandl::Client::Base
|
5
|
-
|
6
|
-
##########
|
7
|
-
# SCOPES #
|
8
|
-
##########
|
9
|
-
|
10
|
-
scope :query, :page, :parent_url_title
|
11
|
-
|
12
|
-
|
13
|
-
################
|
14
|
-
# ASSOCIATIONS #
|
15
|
-
################
|
16
|
-
|
17
|
-
def parent
|
18
|
-
@parent ||= Quandl::Client::Sheet.find(parent_url_title)
|
19
|
-
end
|
20
|
-
|
21
|
-
def children
|
22
|
-
Quandl::Client::Sheet.parent_url_title(self.full_url_title)
|
23
|
-
end
|
24
|
-
|
25
|
-
|
26
|
-
###############
|
27
|
-
# VALIDATIONS #
|
28
|
-
###############
|
29
|
-
|
30
|
-
validates :title, presence: true
|
31
|
-
|
32
|
-
|
33
|
-
##############
|
34
|
-
# PROPERTIES #
|
35
|
-
##############
|
36
|
-
|
37
|
-
attributes :title, :content, :url_title, :full_url_title, :description, :skip_browse
|
38
|
-
|
39
|
-
def html
|
40
|
-
@html ||= self.attributes[:html] || Quandl::Client::Sheet.find(full_url_title).attributes[:html]
|
41
|
-
end
|
42
|
-
|
43
|
-
def parent_url_title
|
44
|
-
@parent_url_title ||= self.full_url_title.split('/')[0..-2].join()
|
45
|
-
end
|
46
|
-
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
1
|
+
module Quandl
|
2
|
+
module Client
|
3
|
+
|
4
|
+
class Sheet < Quandl::Client::Base
|
5
|
+
|
6
|
+
##########
|
7
|
+
# SCOPES #
|
8
|
+
##########
|
9
|
+
|
10
|
+
scope :query, :page, :parent_url_title
|
11
|
+
|
12
|
+
|
13
|
+
################
|
14
|
+
# ASSOCIATIONS #
|
15
|
+
################
|
16
|
+
|
17
|
+
def parent
|
18
|
+
@parent ||= Quandl::Client::Sheet.find(parent_url_title)
|
19
|
+
end
|
20
|
+
|
21
|
+
def children
|
22
|
+
Quandl::Client::Sheet.parent_url_title(self.full_url_title)
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
###############
|
27
|
+
# VALIDATIONS #
|
28
|
+
###############
|
29
|
+
|
30
|
+
validates :title, presence: true
|
31
|
+
|
32
|
+
|
33
|
+
##############
|
34
|
+
# PROPERTIES #
|
35
|
+
##############
|
36
|
+
|
37
|
+
attributes :title, :content, :url_title, :full_url_title, :description, :skip_browse
|
38
|
+
|
39
|
+
def html
|
40
|
+
@html ||= self.attributes[:html] || Quandl::Client::Sheet.find(full_url_title).attributes[:html]
|
41
|
+
end
|
42
|
+
|
43
|
+
def parent_url_title
|
44
|
+
@parent_url_title ||= self.full_url_title.split('/')[0..-2].join()
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
51
|
end
|
@@ -1,49 +1,49 @@
|
|
1
|
-
module Quandl
|
2
|
-
module Client
|
3
|
-
|
4
|
-
class Source < Quandl::Client::Base
|
5
|
-
|
6
|
-
class << self
|
7
|
-
|
8
|
-
def cached
|
9
|
-
@@cached ||= {}
|
10
|
-
end
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
##########
|
15
|
-
# SCOPES #
|
16
|
-
##########
|
17
|
-
|
18
|
-
scope :query
|
19
|
-
scope :page, ->(p){ where( page: p.to_i )}
|
20
|
-
scope :code, ->(c){ where( code: c.to_s.upcase )}
|
21
|
-
|
22
|
-
|
23
|
-
###############
|
24
|
-
# ASSOCIATIONS #
|
25
|
-
###############
|
26
|
-
|
27
|
-
def datasets
|
28
|
-
Quandl::Client::Dataset.source_code(code)
|
29
|
-
end
|
30
|
-
|
31
|
-
|
32
|
-
###############
|
33
|
-
# VALIDATIONS #
|
34
|
-
###############
|
35
|
-
|
36
|
-
validates :code, presence: true, length: { minimum: 2 }, format: { with: Quandl::Pattern.code, message: "is invalid. Expected format: #{Quandl::Pattern.code.to_example}" }
|
37
|
-
validates :host, :name, presence: true
|
38
|
-
|
39
|
-
|
40
|
-
##############
|
41
|
-
# PROPERTIES #
|
42
|
-
##############
|
43
|
-
|
44
|
-
attributes :code, :name, :host, :description, :datasets_count, :use_proxy, :type, :concurrency
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
1
|
+
module Quandl
|
2
|
+
module Client
|
3
|
+
|
4
|
+
class Source < Quandl::Client::Base
|
5
|
+
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def cached
|
9
|
+
@@cached ||= {}
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
##########
|
15
|
+
# SCOPES #
|
16
|
+
##########
|
17
|
+
|
18
|
+
scope :query
|
19
|
+
scope :page, ->(p){ where( page: p.to_i )}
|
20
|
+
scope :code, ->(c){ where( code: c.to_s.upcase )}
|
21
|
+
|
22
|
+
|
23
|
+
###############
|
24
|
+
# ASSOCIATIONS #
|
25
|
+
###############
|
26
|
+
|
27
|
+
def datasets
|
28
|
+
Quandl::Client::Dataset.source_code(code)
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
###############
|
33
|
+
# VALIDATIONS #
|
34
|
+
###############
|
35
|
+
|
36
|
+
validates :code, presence: true, length: { minimum: 2 }, format: { with: Quandl::Pattern.code, message: "is invalid. Expected format: #{Quandl::Pattern.code.to_example}" }
|
37
|
+
validates :host, :name, presence: true
|
38
|
+
|
39
|
+
|
40
|
+
##############
|
41
|
+
# PROPERTIES #
|
42
|
+
##############
|
43
|
+
|
44
|
+
attributes :code, :name, :host, :description, :datasets_count, :use_proxy, :type, :concurrency
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
49
|
end
|
@@ -1,66 +1,66 @@
|
|
1
|
-
class Quandl::Client::Superset < Quandl::Client::Base
|
2
|
-
|
3
|
-
scope :query, :page, :owner, :code, :source_code
|
4
|
-
|
5
|
-
attributes :id, :source_code, :code, :name, :urlize_name, :description, :updated_at, :private
|
6
|
-
attributes :column_codes, :column_names
|
7
|
-
attributes :frequency, :from_date, :to_date
|
8
|
-
|
9
|
-
validates :code, presence: true, format: { with: Quandl::Pattern.code, message: "is invalid. Expected format: #{Quandl::Pattern.code.to_example}" }
|
10
|
-
validates :column_codes, presence: true
|
11
|
-
validate :column_codes_should_be_valid!
|
12
|
-
|
13
|
-
def self.find_or_build( attributes={} )
|
14
|
-
attrs = attributes.symbolize_keys!
|
15
|
-
# by id
|
16
|
-
record = self.find(attrs[:id]) if attrs[:id].present?
|
17
|
-
# by source_code/code
|
18
|
-
record = self.find(File.join(attrs[:source_code], attrs[:code])) if !record.try(:exists?) && attrs[:source_code].present? && attrs[:code].present?
|
19
|
-
# by code
|
20
|
-
record = self.find(attrs[:code]) if !record.try(:exists?) && attrs[:code].present?
|
21
|
-
# build
|
22
|
-
record = self.new unless record.try(:exists?)
|
23
|
-
record.assign_attributes(attrs)
|
24
|
-
record
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.example
|
28
|
-
self.new( code: "SUPERSET_EXAMPLE", name: "Superset Name", description: "Superset description", column_codes: ['NSE.OIL.1'], column_names: ['Column Name'] )
|
29
|
-
end
|
30
|
-
|
31
|
-
def data
|
32
|
-
@data ||= Quandl::Client::Dataset::Data.with_id(id)
|
33
|
-
end
|
34
|
-
|
35
|
-
def full_url
|
36
|
-
File.join(Quandl::Client::Base.url.gsub(/api\/?/, ''), full_code)
|
37
|
-
end
|
38
|
-
|
39
|
-
def full_code
|
40
|
-
File.join(self.source_code.to_s, self.code.to_s)
|
41
|
-
end
|
42
|
-
|
43
|
-
protected
|
44
|
-
|
45
|
-
def column_codes_should_be_valid!
|
46
|
-
# must be an array
|
47
|
-
unless column_codes.respond_to?(:each)
|
48
|
-
# failure
|
49
|
-
self.errors.add( :column_codes, "expected an array, but got #{column_codes.class}.")
|
50
|
-
# nothing more to do
|
51
|
-
return false
|
52
|
-
end
|
53
|
-
# check each code
|
54
|
-
column_codes.each do |code|
|
55
|
-
# is the code valid?
|
56
|
-
next if code =~ /#{Quandl::Pattern.code}\.#{Quandl::Pattern.code}\.[0-9]+/
|
57
|
-
# otherwise report error
|
58
|
-
self.errors.add( :column_codes, "Code '#{code}' is invalid. Expected: /#{Quandl::Pattern.code.to_example}.#{Quandl::Pattern.code.to_example}.INTEGER/" )
|
59
|
-
# nothing more to do here
|
60
|
-
return false
|
61
|
-
end
|
62
|
-
# success
|
63
|
-
true
|
64
|
-
end
|
65
|
-
|
1
|
+
class Quandl::Client::Superset < Quandl::Client::Base
|
2
|
+
|
3
|
+
scope :query, :page, :owner, :code, :source_code
|
4
|
+
|
5
|
+
attributes :id, :source_code, :code, :name, :urlize_name, :description, :updated_at, :private
|
6
|
+
attributes :column_codes, :column_names
|
7
|
+
attributes :frequency, :from_date, :to_date
|
8
|
+
|
9
|
+
validates :code, presence: true, format: { with: Quandl::Pattern.code, message: "is invalid. Expected format: #{Quandl::Pattern.code.to_example}" }
|
10
|
+
validates :column_codes, presence: true
|
11
|
+
validate :column_codes_should_be_valid!
|
12
|
+
|
13
|
+
def self.find_or_build( attributes={} )
|
14
|
+
attrs = attributes.symbolize_keys!
|
15
|
+
# by id
|
16
|
+
record = self.find(attrs[:id]) if attrs[:id].present?
|
17
|
+
# by source_code/code
|
18
|
+
record = self.find(File.join(attrs[:source_code], attrs[:code])) if !record.try(:exists?) && attrs[:source_code].present? && attrs[:code].present?
|
19
|
+
# by code
|
20
|
+
record = self.find(attrs[:code]) if !record.try(:exists?) && attrs[:code].present?
|
21
|
+
# build
|
22
|
+
record = self.new unless record.try(:exists?)
|
23
|
+
record.assign_attributes(attrs)
|
24
|
+
record
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.example
|
28
|
+
self.new( code: "SUPERSET_EXAMPLE", name: "Superset Name", description: "Superset description", column_codes: ['NSE.OIL.1'], column_names: ['Column Name'] )
|
29
|
+
end
|
30
|
+
|
31
|
+
def data
|
32
|
+
@data ||= Quandl::Client::Dataset::Data.with_id(id)
|
33
|
+
end
|
34
|
+
|
35
|
+
def full_url
|
36
|
+
File.join(Quandl::Client::Base.url.gsub(/api\/?/, ''), full_code)
|
37
|
+
end
|
38
|
+
|
39
|
+
def full_code
|
40
|
+
File.join(self.source_code.to_s, self.code.to_s)
|
41
|
+
end
|
42
|
+
|
43
|
+
protected
|
44
|
+
|
45
|
+
def column_codes_should_be_valid!
|
46
|
+
# must be an array
|
47
|
+
unless column_codes.respond_to?(:each)
|
48
|
+
# failure
|
49
|
+
self.errors.add( :column_codes, "expected an array, but got #{column_codes.class}.")
|
50
|
+
# nothing more to do
|
51
|
+
return false
|
52
|
+
end
|
53
|
+
# check each code
|
54
|
+
column_codes.each do |code|
|
55
|
+
# is the code valid?
|
56
|
+
next if code =~ /#{Quandl::Pattern.code}\.#{Quandl::Pattern.code}\.[0-9]+/
|
57
|
+
# otherwise report error
|
58
|
+
self.errors.add( :column_codes, "Code '#{code}' is invalid. Expected: /#{Quandl::Pattern.code.to_example}.#{Quandl::Pattern.code.to_example}.INTEGER/" )
|
59
|
+
# nothing more to do here
|
60
|
+
return false
|
61
|
+
end
|
62
|
+
# success
|
63
|
+
true
|
64
|
+
end
|
65
|
+
|
66
66
|
end
|
@@ -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
|
data/lib/quandl/client.rb
CHANGED
@@ -1,54 +1,55 @@
|
|
1
|
-
require "quandl/client/version"
|
2
|
-
|
3
|
-
require 'scope_composer'
|
4
|
-
require 'her'
|
5
|
-
require 'quandl/her/remove_method_data'
|
6
|
-
require 'quandl/
|
7
|
-
require
|
8
|
-
|
9
|
-
|
10
|
-
require 'quandl/pattern
|
11
|
-
|
12
|
-
|
13
|
-
require 'quandl/client/
|
14
|
-
require 'quandl/client/
|
15
|
-
require 'quandl/client/models/
|
16
|
-
require 'quandl/client/models/
|
17
|
-
require 'quandl/client/models/
|
18
|
-
require 'quandl/client/models/
|
19
|
-
require 'quandl/client/models/
|
20
|
-
require 'quandl/client/models/
|
21
|
-
require 'quandl/client/models/
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
1
|
+
require "quandl/client/version"
|
2
|
+
|
3
|
+
require 'scope_composer'
|
4
|
+
require 'her'
|
5
|
+
require 'quandl/her/remove_method_data'
|
6
|
+
require 'quandl/her/collection'
|
7
|
+
require 'quandl/logger'
|
8
|
+
require "quandl/data"
|
9
|
+
|
10
|
+
require 'quandl/pattern'
|
11
|
+
require 'quandl/pattern/client'
|
12
|
+
|
13
|
+
require 'quandl/client/middleware'
|
14
|
+
require 'quandl/client/base'
|
15
|
+
require 'quandl/client/models/dataset'
|
16
|
+
require 'quandl/client/models/sheet'
|
17
|
+
require 'quandl/client/models/source'
|
18
|
+
require 'quandl/client/models/user'
|
19
|
+
require 'quandl/client/models/location'
|
20
|
+
require 'quandl/client/models/scraper'
|
21
|
+
require 'quandl/client/models/report'
|
22
|
+
require 'quandl/client/models/superset'
|
23
|
+
|
24
|
+
module Quandl
|
25
|
+
module Client
|
26
|
+
|
27
|
+
class << self
|
28
|
+
|
29
|
+
attr_accessor :request_source, :request_version, :request_platform
|
30
|
+
|
31
|
+
def request_source
|
32
|
+
@request_source ||= "quandl_client"
|
33
|
+
end
|
34
|
+
|
35
|
+
def request_version
|
36
|
+
@request_version ||= Quandl::Client::VERSION
|
37
|
+
end
|
38
|
+
|
39
|
+
def request_platform
|
40
|
+
@request_platform ||= RUBY_PLATFORM
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.use(url)
|
46
|
+
Quandl::Client::Base.use(url)
|
47
|
+
end
|
48
|
+
def self.token=(value)
|
49
|
+
Quandl::Client::Base.token = value
|
50
|
+
end
|
51
|
+
|
52
|
+
HTTP_STATUS_CODES = {100=>"Continue", 101=>"Switching Protocols", 102=>"Processing", 200=>"OK", 201=>"Created", 202=>"Accepted", 203=>"Non-Authoritative Information", 204=>"No Content", 205=>"Reset Content", 206=>"Partial Content", 207=>"Multi-Status", 208=>"Already Reported", 226=>"IM Used", 300=>"Multiple Choices", 301=>"Moved Permanently", 302=>"Found", 303=>"See Other", 304=>"Not Modified", 305=>"Use Proxy", 306=>"Reserved", 307=>"Temporary Redirect", 308=>"Permanent Redirect", 400=>"Bad Request", 401=>"Unauthorized", 402=>"Payment Required", 403=>"Forbidden", 404=>"Not Found", 405=>"Method Not Allowed", 406=>"Not Acceptable", 407=>"Proxy Authentication Required", 408=>"Request Timeout", 409=>"Conflict", 410=>"Gone", 411=>"Length Required", 412=>"Precondition Failed", 413=>"Request Entity Too Large", 414=>"Request-URI Too Long", 415=>"Unsupported Media Type", 416=>"Requested Range Not Satisfiable", 417=>"Expectation Failed", 422=>"Unprocessable Entity", 423=>"Locked", 424=>"Failed Dependency", 425=>"Reserved for WebDAV advanced collections expired proposal", 426=>"Upgrade Required", 427=>"Unassigned", 428=>"Precondition Required", 429=>"Too Many Requests", 430=>"Unassigned", 431=>"Request Header Fields Too Large", 500=>"Internal Server Error", 501=>"Not Implemented", 502=>"Bad Gateway", 503=>"Service Unavailable", 504=>"Gateway Timeout", 505=>"HTTP Version Not Supported", 506=>"Variant Also Negotiates (Experimental)", 507=>"Insufficient Storage", 508=>"Loop Detected", 509=>"Unassigned", 510=>"Not Extended", 511=>"Network Authentication Required"}
|
53
|
+
|
54
|
+
end
|
54
55
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Her
|
2
|
+
module Model
|
3
|
+
module Attributes
|
4
|
+
def self.initialize_collection(klass, parsed_data={})
|
5
|
+
arr = klass.extract_array(parsed_data)
|
6
|
+
arr = [] unless arr.is_a?(Array)
|
7
|
+
collection_data = arr.map do |item_data|
|
8
|
+
resource = klass.new(klass.parse(item_data))
|
9
|
+
resource.run_callbacks :find
|
10
|
+
resource
|
11
|
+
end
|
12
|
+
Her::Collection.new(collection_data, parsed_data[:metadata], parsed_data[:errors])
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
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
|
@@ -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/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
|