Sha256: db5e51420b97f32aad7e5ec89d4d6bb58cde1c7a7f529e7e63724f2a8b97f834

Contents?: true

Size: 778 Bytes

Versions: 25

Compression:

Stored size: 778 Bytes

Contents

class Quandl::Format::Dataset::Dump
  
  class << self

    def collection(*args)
      Array(args).flatten.collect{|r| record(r) }.join("\n")
    end

    def record(record)
      self.new(record).to_qdf
    end

  end

  attr_accessor :record

  def initialize(r)
    self.record = r
  end

  def to_qdf
    [ 
      meta_attributes,
      column_names,
      data
    ].compact.join
  end

  def meta_attributes
    record.meta_attributes.stringify_keys.to_yaml[4..-1] + "-\n"
  end
  
  def data
    data = record.data
    data = data.collect(&:to_csv).join if data.is_a?(Array) && data.first.respond_to?(:to_csv)
    data = data.to_csv if data.respond_to?(:to_csv)
    data
  end

  def column_names
    record.column_names.to_csv if record.column_names.present?
  end

end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
quandl_format-0.1.4 lib/quandl/format/dataset/dump.rb
quandl_format-0.1.3 lib/quandl/format/dataset/dump.rb
quandl_format-0.1.2 lib/quandl/format/dataset/dump.rb
quandl_format-0.1.1 lib/quandl/format/dataset/dump.rb
quandl_format-0.1.0 lib/quandl/format/dataset/dump.rb