Sha256: 39c29ec17dcffd9782933a77a3cdc12803d82e633b5c6d4633319f90db6e6f5a

Contents?: true

Size: 1004 Bytes

Versions: 1

Compression:

Stored size: 1004 Bytes

Contents

class Quandl::Operation::QDFormat::Node
  
  ATTRIBUTES = :source_code, :code, :name, :description, :column_names
  attr_accessor *ATTRIBUTES

  attr_accessor :data

  def initialize(attrs)
    assign_attributes(attrs)
  end

  def assign_attributes(attrs)
    attrs.each do |key, value|
      self.send("#{key}=", value) if self.respond_to?(key)
    end
  end

  def attributes
    ATTRIBUTES.inject({}){|m,k| m[k] = self.send(k); m }
  end

  def inspect
    "<##{self.class.name} #{attributes.to_s} >"
  end

  def full_code=(value)
    value = value.split('/')
    self.source_code = value[0]
    self.code = value[1]
  end

  def full_code
    [source_code, code].join('/')
  end

  def data=(rows)
    self.column_names = rows.shift unless rows.first.collect{|r| r.to_s.numeric? }.include?(true)
    @data = rows
  end

  def column_names=(names)
    @column_names = Array(names).flatten.collect{|n| n.strip.rstrip }
  end

  def to_qdf
    Quandl::Operation::QDFormat::Dump.node(self)
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
quandl_operation-0.1.19 lib/quandl/operation/qdformat/node.rb