module Quandl::Format::Dataset::Attributes

Public Class Methods

new(*args) click to toggle source
# File lib/quandl/format/dataset/attributes.rb, line 35
def initialize(*args)
  attrs = args.extract_options!
  assign_attributes(attrs) if attrs.is_a?(Hash)
end

Public Instance Methods

assign_attributes(attrs) click to toggle source
# File lib/quandl/format/dataset/attributes.rb, line 40
def assign_attributes(attrs)
  attrs.each do |key, value|
    raise_unknown_attribute_error!(key) unless respond_to?(key)
    self.send("#{key}=", value) 
  end
end
attributes() click to toggle source
# File lib/quandl/format/dataset/attributes.rb, line 84
def attributes
  self.class.attribute_names.inject({}){|m,k| m[k] = self.send(k) unless self.send(k).nil?; m }
end
column_names() click to toggle source
# File lib/quandl/format/dataset/attributes.rb, line 68
def column_names
  @column_names ||= []
end
column_names=(names) click to toggle source
# File lib/quandl/format/dataset/attributes.rb, line 72
def column_names=(names)
  @column_names = Array(names).flatten.collect{|n| n.strip.rstrip }
end
data=(rows) click to toggle source
# File lib/quandl/format/dataset/attributes.rb, line 61
def data=(rows)
  rows = rows.to_table if rows.respond_to?(:to_table)
  @data = Quandl::Data.new(rows)
  self.column_names = @data.headers if @data.headers.present?
  @data
end
description=(value) click to toggle source
# File lib/quandl/format/dataset/attributes.rb, line 57
def description=(value)
  @description = value.to_s.gsub('\n', "\n")
end
full_code() click to toggle source
# File lib/quandl/format/dataset/attributes.rb, line 53
def full_code
  [source_code, code].collect{|v| v.blank? ? nil : v }.compact.join('/')
end
full_code=(value) click to toggle source
# File lib/quandl/format/dataset/attributes.rb, line 47
def full_code=(value)
  value = value.split('/')
  self.source_code = value[0]
  self.code = value[1]
end
meta_attributes() click to toggle source
# File lib/quandl/format/dataset/attributes.rb, line 80
def meta_attributes
  self.class.meta_attribute_names.inject({}){|m,k| m[k] = self.send(k); m }
end
to_qdf() click to toggle source
# File lib/quandl/format/dataset/attributes.rb, line 76
def to_qdf
  Dump.record(self)
end

Private Instance Methods

raise_unknown_attribute_error!(key) click to toggle source
# File lib/quandl/format/dataset/attributes.rb, line 90
def raise_unknown_attribute_error!(key)
  m = "Unknown Field '#{key}' valid fields are: #{self.class.meta_attribute_names.join(', ')}"
  raise Quandl::Error::UnknownAttribute, m
end