<commit_before>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<commit_msg>add superset full_url, full_code<commit_after>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
  
  def full_url
    File.join(Quandl::Client::Base.url.gsub('api/', ''), full_code)
  end
  
  def full_code
    File.join(self.source_code.to_s, self.code.to_s)
  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
{'fraction_non_alphanumeric': 0.131227613155324, 'fraction_numerical': 0.0006512536633018561, 'mean_word_length': 4.351916376306621, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '392840', 'n_tokens_mistral': 1016, 'n_tokens_neox': 1023, 'n_words': 238}