<commit_before>class Quandl::Client::Dataset < Quandl::Client::Base
  
  require 'quandl/client/models/dataset/data'

  ##########  
  # SCOPES #
  ##########
  class << self
    def touch_existing(id)
      put(File.join(Quandl::Client::Base.url_with_version, "datasets/#{id}/touch")).exists?
    end
  
    def find(value)
      # enforce code formatting
      if value.is_a?(String)
        # strip extra whitespace
        value = value.strip.rstrip
        # ensure slashes are forward facing
        value = value.gsub("\\","/").gsub(".","/")
        # ensure uppercase
        value = value.upcase
      end
      # short-circuit if value is illegal
      return nil unless value.is_a?(Integer) || value.to_s =~ %r{^#{Quandl::Pattern.full_code}$}
      super(value)
    end
  
  end
  
  # SEARCH
  scope :query, :rows
  scope :page, ->(p){ where( page: p.to_i )}
  scope :source_code, ->(c){ where( code: c.to_s.upcase )}
  
  ###############
  # ASSOCIATIONS #
  ###############
   
  def source
    @source ||= Quandl::Client::Source.find(self.source_code)
  end
  
  ###############
  # VALIDATIONS #
  ###############
  
  validates :code, presence: true, format: { with: Quandl::Pattern.code, message: "is invalid. Expected format: #{Quandl::Pattern.code.to_example}" }
  validates :display_url, allow_blank: true, url: true
  validate :data_should_be_valid!
  validate :dataset_data_should_be_valid!
  validate :data_row_count_should_match_column_count!
  validate :data_columns_should_not_exceed_column_names!
  validate :data_rows_should_have_equal_columns!
  validate :ambiguous_code_requires_source_code!
  
  
  ##############
  # PROPERTIES #<commit_msg>add scope Dataset.owner for filtering by owner<commit_after>class Quandl::Client::Dataset < Quandl::Client::Base
  
  require 'quandl/client/models/dataset/data'

  ##########  
  # SCOPES #
  ##########
  class << self
    def touch_existing(id)
      put(File.join(Quandl::Client::Base.url_with_version, "datasets/#{id}/touch")).exists?
    end
  
    def find(value)
      # enforce code formatting
      if value.is_a?(String)
        # strip extra whitespace
        value = value.strip.rstrip
        # ensure slashes are forward facing
        value = value.gsub("\\","/").gsub(".","/")
        # ensure uppercase
        value = value.upcase
      end
      # short-circuit if value is illegal
      return nil unless value.is_a?(Integer) || value.to_s =~ %r{^#{Quandl::Pattern.full_code}$}
      super(value)
    end
  
  end
  
  # SEARCH
  scope :query, :rows, :owner
  scope :page, ->(p){ where( page: p.to_i )}
  scope :source_code, ->(c){ where( code: c.to_s.upcase )}
  
  ###############
  # ASSOCIATIONS #
  ###############
   
  def source
    @source ||= Quandl::Client::Source.find(self.source_code)
  end
  
  ###############
  # VALIDATIONS #
  ###############
  
  validates :code, presence: true, format: { with: Quandl::Pattern.code, message: "is invalid. Expected format: #{Quandl::Pattern.code.to_example}" }
  validates :display_url, allow_blank: true, url: true
  validate :data_should_be_valid!
  validate :dataset_data_should_be_valid!
  validate :data_row_count_should_match_column_count!
  validate :data_columns_should_not_exceed_column_names!
  validate :data_rows_should_have_equal_columns!
  validate :ambiguous_code_requires_source_code!
  
  
  ##############
  # PROPERTIES #
{'fraction_non_alphanumeric': 0.17025671289465918, 'fraction_numerical': 0.0, 'mean_word_length': 3.4900662251655628, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '2745989', 'n_tokens_mistral': 1168, 'n_tokens_neox': 1154, 'n_words': 219}