Class: Quandl::ModelBase

Inherits:
Object
  • Object
show all
Defined in:
lib/quandl/model/base.rb

Direct Known Subclasses

Data, Database, Dataset

Instance Method Summary collapse

Constructor Details

#initialize(data, _options = {}) ⇒ ModelBase

Returns a new instance of ModelBase.



3
4
5
# File 'lib/quandl/model/base.rb', line 3

def initialize(data, _options = {})
  @raw_data = ActiveSupport::HashWithIndifferentAccess.new(Hash[data.map { |k, v| [Quandl::Util.methodize(k), v] }])
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object (private)



25
26
27
28
29
# File 'lib/quandl/model/base.rb', line 25

def method_missing(method_name, *args, &block)
  return @raw_data[method_name.to_s] if @raw_data.key?(method_name.to_s)
  return @raw_data.method(method_name.to_s).call(*args, &block) if @raw_data.respond_to?(method_name.to_s)
  super
end

Instance Method Details

#column_namesObject



11
12
13
# File 'lib/quandl/model/base.rb', line 11

def column_names
  @raw_data.keys.map(&:to_s).map(&:titleize)
end

#data_fieldsObject



7
8
9
# File 'lib/quandl/model/base.rb', line 7

def data_fields
  @raw_data.keys.map(&:to_s)
end

#inspectObject



19
20
21
# File 'lib/quandl/model/base.rb', line 19

def inspect
  @raw_data.to_s
end

#to_aObject



15
16
17
# File 'lib/quandl/model/base.rb', line 15

def to_a
  @raw_data.values
end