Sha256: 1a607b20f1f931e9581d611e3dc22adc9c0de2b8e9323f88a754061dbde3e6d7

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

require 'quandl/cassinatra/model/dataset/searchable'

module Quandl
module Cassinatra
module Model

class Dataset
  
  include Concerns::Properties
  include Searchable

  attributes :id, :data, :trim_start, :trim_end, :columns

  delegate :columns_count, :created_at, :frequency, :rows_count, :type, :updated_at, to: :dataset_attribute
  
  def column_units
    @column_units ||= columns.collect{|c| c['units'] }
  end
  
  def column_names
    @column_names ||= columns.collect{|c| c['name'] }
  end
  
  def column_ids
    @column_ids ||= columns.collect{|c| c['id'] }
  end
  
  def data_table
    @data_table ||= Data::Table.new( self.data || [] )
  end
  def data_table=(value)
    self.data = Data::Table.new(value).to_csv
  end
  
  def dataset_attribute(*args)
    return @dataset_attribute if @dataset_attribute
    # options
    options = args.extract_options!
    count = options[:count] == true
    # grab dataset_attribute
    @dataset_attribute = DatasetAttribute.where( count: count ).find(id)
  end

  def delete_data
    Dataset.destroy_existing("#{id.to_i}/data").status
  end

  def delete_rows(*dates)
    query = { dates: Array(dates).flatten }.to_query
    Dataset.destroy_existing("#{id.to_i}/data/rows?#{query}").status
  end

end
end
end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
quandl_cassinatra-0.2.2 lib/quandl/cassinatra/model/dataset.rb