Class: Quandl::Client::Dataset

Inherits:
Base
  • Object
show all
Defined in:
lib/quandl/client/models/dataset.rb

Defined Under Namespace

Classes: Data

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

her_api, models, models_use_her_api!, use

Class Method Details

.touch_existing(id) ⇒ Object

SCOPES #



12
13
14
# File 'lib/quandl/client/models/dataset.rb', line 12

def self.touch_existing(id)
  put(File.join(Quandl::Client::Base.url, "datasets/#{id}/touch")).exists?
end

Instance Method Details

#dataObject

DATA



58
59
60
# File 'lib/quandl/client/models/dataset.rb', line 58

def data
  dataset_data.data? ? dataset_data.data : Quandl::Client::Dataset::Data.with_id(id)
end

#data=(value) ⇒ Object



62
63
64
# File 'lib/quandl/client/models/dataset.rb', line 62

def data=(value)
  dataset_data.data = value
end

#dataset_dataObject



82
83
84
# File 'lib/quandl/client/models/dataset.rb', line 82

def dataset_data
  @dataset_data ||= Quandl::Client::Dataset::Data.new( id: id )
end

#delete_dataObject



66
67
68
69
70
71
# File 'lib/quandl/client/models/dataset.rb', line 66

def delete_data
  # cant delete unsaved records
  return false if new_record?
  # delete and return success / failure
  self.class.destroy_existing("#{id}/data").saved?
end

#delete_rows(*dates) ⇒ Object



73
74
75
76
77
78
79
80
# File 'lib/quandl/client/models/dataset.rb', line 73

def delete_rows(*dates)
  # cant delete unsaved records
  return false if new_record?
  # collect dates
  query = { dates: Array(dates).flatten }.to_query
  # delete and return success / failure
  self.class.destroy_existing("#{id}/data/rows?#{query}").saved?
end

#enforce_required_formatsObject (protected)



97
98
99
100
# File 'lib/quandl/client/models/dataset.rb', line 97

def enforce_required_formats
  # self.data = Quandl::Data.new(data).to_csv
  self.locations_attributes = locations_attributes.to_json if locations_attributes.respond_to?(:to_json) && !locations_attributes.kind_of?(String)
end

#full_codeObject



52
53
54
# File 'lib/quandl/client/models/dataset.rb', line 52

def full_code
  @full_code ||= File.join(self.source_code, self.code)
end

#save_dataset_dataObject (protected)



90
91
92
93
94
95
# File 'lib/quandl/client/models/dataset.rb', line 90

def save_dataset_data
  dataset_data.id = id
  dataset_data.save
  # update dataset's attributes with dataset_data's attributes
  attributes.each{|k,v| attributes[k] = dataset_data.attributes[k] if dataset_data.attributes.has_key?(k) }
end

#sourceObject

ASSOCIATIONS #



25
26
27
# File 'lib/quandl/client/models/dataset.rb', line 25

def source
  @source ||= Quandl::Client::Source.find(self.source_code)
end