Sha256: 9897ffb33084721c581c9814119173fcc75aea837604c5945d05c7640a98d59c
Contents?: true
Size: 1.83 KB
Versions: 1
Compression:
Stored size: 1.83 KB
Contents
class Quandl::Client::Superset < Quandl::Client::Base scope :query, :page, :owner, :code, :source_code attributes :id, :source_code, :code, :name, :urlize_name, :description, :updated_at, :private attributes :column_codes, :column_names attributes :frequency, :from_date, :to_date validates :code, presence: true, format: { with: Quandl::Pattern.code, message: "is invalid. Expected format: #{Quandl::Pattern.code.to_example}" } validates :column_codes, presence: true validate :column_codes_should_be_valid! def self.find_or_build( attributes={} ) record = self.find(attributes[:id]) if attributes[:id].present? record = self.where( attributes.slice(:code, :source_code).merge( owner: 'myself' ) ).first unless record.try(:exists?) record = self.new unless record.try(:exists?) record.assign_attributes(attributes) record end def self.example self.new( code: "SUPERSET_EXAMPLE", name: "Superset Name", description: "Superset description", column_codes: ['NSE.OIL.1'], column_names: ['Column Name'] ) end def data @data ||= Quandl::Client::Dataset::Data.with_id(id) end protected 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 end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
quandl_client-2.7.2 | lib/quandl/client/models/superset.rb |