Class: Quandl::Client::Superset

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

Constant Summary

Constants inherited from Base

Base::TOKEN_THREAD_KEY

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

her_api, models, models_use_her_api!, threadsafe_token!, threadsafe_token?, url_with_version, use

Class Method Details

.exampleObject



27
28
29
# File 'lib/quandl/client/models/superset.rb', line 27

def self.example
  self.new( code: "SUPERSET_EXAMPLE", name: "Superset Name", description: "Superset description", column_codes: ['NSE.OIL.1'], column_names: ['Column Name'] )
end

.find_or_build(attributes = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/quandl/client/models/superset.rb', line 13

def self.find_or_build( attributes={} )
  attrs = attributes.symbolize_keys!
  # by id
  record = self.find(attrs[:id]) if attrs[:id].present?
  # by source_code/code
  record = self.find(File.join(attrs[:source_code], attrs[:code])) if !record.try(:exists?) && attrs[:source_code].present? && attrs[:code].present?
  # by code
  record = self.find(attrs[:code]) if !record.try(:exists?) && attrs[:code].present?
  # build
  record = self.new unless record.try(:exists?)
  record.assign_attributes(attrs)
  record
end

Instance Method Details

#column_codes_should_be_valid!Object (protected)



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/quandl/client/models/superset.rb', line 45

def column_codes_should_be_valid!
  # must be an array
  unless column_codes.respond_to?(:each)
    # failure
    self.errors.add( :column_codes, "expected an array, but got #{column_codes.class}.")
    # nothing more to do
    return false
  end
  # check each code
  column_codes.each do |code|
    # is the code valid?
    next if code =~ /#{Quandl::Pattern.code}\.#{Quandl::Pattern.code}\.[0-9]+/
    # otherwise report error
    self.errors.add( :column_codes, "Code '#{code}' is invalid. Expected: /#{Quandl::Pattern.code.to_example}.#{Quandl::Pattern.code.to_example}.INTEGER/" )
    # nothing more to do here
    return false
  end
  # success
  true
end

#dataObject



31
32
33
# File 'lib/quandl/client/models/superset.rb', line 31

def data
  @data ||= Quandl::Client::Dataset::Data.with_id(id)
end

#full_codeObject



39
40
41
# File 'lib/quandl/client/models/superset.rb', line 39

def full_code
  File.join(self.source_code.to_s, self.code.to_s)
end

#full_urlObject



35
36
37
# File 'lib/quandl/client/models/superset.rb', line 35

def full_url
  File.join(Quandl::Client::Base.url.gsub(/api\/?/, ''), full_code)
end