Class: Quandl::Client::Dataset
- Inherits:
-
Base
- Object
- Base
- Quandl::Client::Dataset
show all
- Includes:
- Benchmark, Validations
- Defined in:
- lib/quandl/client/models/dataset.rb,
lib/quandl/client/models/dataset/benchmark.rb,
lib/quandl/client/models/dataset/validations.rb
Defined Under Namespace
Modules: Benchmark, Validations
Classes: Data
Class Method Summary
collapse
Instance Method Summary
collapse
#ambiguous_code_requires_source_code!, #data_columns_should_not_exceed_column_names!, #data_row_count_should_match_column_count!, #data_rows_should_have_equal_columns!, #data_should_be_valid!, #dataset_data_should_be_valid!, #enforce_required_formats, #inherit_errors, #save_dataset_data, #source_code_should_exist!
Methods inherited from Base
her_api, models, models_use_her_api!, url_with_version, use
Class Method Details
.find(value) ⇒ Object
18
19
20
21
22
23
24
25
|
# File 'lib/quandl/client/models/dataset.rb', line 18
def find(value)
value = format_id(value)
return nil unless value.is_a?(Integer) || value.to_s =~ %r{^#{Quandl::Pattern.full_code}$}
super(value)
end
|
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/quandl/client/models/dataset.rb', line 27
def format_id(value)
if value.is_a?(String)
value = value.strip.rstrip
value = value.gsub("\\","/").gsub(".","/")
value = value.upcase
end
value
end
|
.touch_existing(id) ⇒ Object
14
15
16
|
# File 'lib/quandl/client/models/dataset.rb', line 14
def touch_existing(id)
put(File.join(Quandl::Client::Base.url_with_version, "datasets/#{id}/touch")).exists?
end
|
Instance Method Details
#code=(v) ⇒ Object
103
104
105
|
# File 'lib/quandl/client/models/dataset.rb', line 103
def code=(v)
write_attribute(:code, sanitize_code(v) )
end
|
#data ⇒ Object
91
92
93
|
# File 'lib/quandl/client/models/dataset.rb', line 91
def data
defined?(@data) ? @data : data_scope
end
|
#data=(value) ⇒ Object
95
96
97
|
# File 'lib/quandl/client/models/dataset.rb', line 95
def data=(value)
@data = Quandl::Data.new(value).sort_descending
end
|
#data? ⇒ Boolean
99
100
101
|
# File 'lib/quandl/client/models/dataset.rb', line 99
def data?
@data.is_a?(Quandl::Data)
end
|
#data_scope ⇒ Object
131
132
133
|
# File 'lib/quandl/client/models/dataset.rb', line 131
def data_scope
@data_scope ||= Quandl::Client::Dataset::Data.with_id(id)
end
|
#dataset_data ⇒ Object
135
136
137
|
# File 'lib/quandl/client/models/dataset.rb', line 135
def dataset_data
@dataset_data ||= Quandl::Client::Dataset::Data.new( id: id )
end
|
#dataset_data? ⇒ Boolean
139
140
141
|
# File 'lib/quandl/client/models/dataset.rb', line 139
def dataset_data?
@dataset_data.is_a?(Quandl::Client::Dataset::Data)
end
|
#delete_data ⇒ Object
115
116
117
118
119
120
|
# File 'lib/quandl/client/models/dataset.rb', line 115
def delete_data
return false if new_record?
self.class.destroy_existing("#{id}/data").saved?
end
|
#delete_rows(*dates) ⇒ Object
122
123
124
125
126
127
128
129
|
# File 'lib/quandl/client/models/dataset.rb', line 122
def delete_rows(*dates)
return false if new_record?
query = { dates: Array(dates).flatten }.to_query
self.class.destroy_existing("#{id}/data/rows?#{query}").saved?
end
|
#full_code ⇒ Object
85
86
87
|
# File 'lib/quandl/client/models/dataset.rb', line 85
def full_code
File.join(self.source_code.to_s, self.code.to_s)
end
|
#full_url ⇒ Object
81
82
83
|
# File 'lib/quandl/client/models/dataset.rb', line 81
def full_url
File.join(Quandl::Client::Base.url.gsub(/api\/?/, ''), full_code)
end
|
#reference_url ⇒ Object
73
74
75
|
# File 'lib/quandl/client/models/dataset.rb', line 73
def reference_url
self.display_url
end
|
#reference_url=(value) ⇒ Object
76
77
78
79
|
# File 'lib/quandl/client/models/dataset.rb', line 76
def reference_url=(value)
value = "http://#{value}" if value.present? && !(value =~ /:\/\//)
self.display_url = value
end
|
#reload ⇒ Object
143
144
145
146
147
|
# File 'lib/quandl/client/models/dataset.rb', line 143
def reload
@dataset_data = nil
@data_scope = nil
@full_code = nil
end
|
#sanitize_code(code) ⇒ Object
111
112
113
|
# File 'lib/quandl/client/models/dataset.rb', line 111
def sanitize_code(code)
code.to_s.upcase.gsub(',','')
end
|
#source ⇒ Object
51
52
53
|
# File 'lib/quandl/client/models/dataset.rb', line 51
def source
@source ||= Quandl::Client::Source.find(self.source_code)
end
|
#source_code=(v) ⇒ Object
107
108
109
|
# File 'lib/quandl/client/models/dataset.rb', line 107
def source_code=(v)
write_attribute(:source_code, sanitize_code(v) )
end
|