Class: Quandl::Data
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from ModelBase
#data_fields, #inspect, #to_a
Constructor Details
#initialize(data, options = {}) ⇒ Data
Returns a new instance of Data.
20
21
22
23
24
|
# File 'lib/quandl/model/data.rb', line 20
def initialize(data, options = {})
converted_column_names = options[:meta]['column_names'].map { |cn| Quandl::Util.methodize(cn) }
@raw_data = Quandl::Util.convert_to_dates(Hash[converted_column_names.zip(data)])
@meta = options[:meta]
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
32
33
34
35
|
# File 'lib/quandl/model/data.rb', line 32
def method_missing(method_name, *args, &block)
return @meta[method_name.to_s] if @meta.key?(method_name.to_s)
super
end
|
Class Method Details
.create_list_from_response(_response, data) ⇒ Object
5
6
7
8
9
10
11
12
13
14
|
# File 'lib/quandl/model/data.rb', line 5
def self.create_list_from_response(_response, data)
if data['dataset_data']['data'].length > 0 &&
data['dataset_data']['column_names'].length != data['dataset_data']['data'].first.length
fail InvalidDataError.new('number of column names does not match number of data points in a row!',
nil, nil, data)
end
values = data['dataset_data'].delete('data')
metadata = data['dataset_data']
Quandl::List.new(self, values, metadata)
end
|
.list_path ⇒ Object
16
17
18
|
# File 'lib/quandl/model/data.rb', line 16
def self.list_path
'datasets/:database_code/:dataset_code/data'
end
|
Instance Method Details
#column_names ⇒ Object
26
27
28
|
# File 'lib/quandl/model/data.rb', line 26
def column_names
@meta['column_names']
end
|