Sha256: 9a8e2e679f62acb8734bf162a2cd25e7b9bb9d22f839cdcbeb26b138732f972e

Contents?: true

Size: 716 Bytes

Versions: 6

Compression:

Stored size: 716 Bytes

Contents

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

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

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

    def to_a
      @raw_data.values
    end

    def inspect
      @raw_data.to_s
    end

    private

    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
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
quandl-1.0.3 lib/quandl/model/base.rb
quandl-1.0.2 lib/quandl/model/base.rb
quandl-1.0.1 lib/quandl/model/base.rb
quandl-1.0.0 lib/quandl/model/base.rb
quandl-1.0.0.rc2 lib/quandl/model/base.rb
quandl-1.0.0.rc1 lib/quandl/model/base.rb