<commit_before>require 'active_record'
require 'pry'

module SoftValidate

  def self.included(base)
    base.send :extend, ClassMethods
  end

  module ClassMethods
    # any method placed here will apply to classes, like Hickwall

    def soft_validates_presence_of(attr)
      cattr_accessor :soft_attributes
      self.soft_attributes ||= Array.new
      self.soft_attributes << attr
      send :include, InstanceMethods
    end

    

  end

  module InstanceMethods
    # any method placed here will apply to instaces, like @hickwall
    
    def progress_complete_count
      self.soft_attributes.length
    end
    
    def soft_valid?

      self.soft_attributes.each do |a|
        return false if self.attributes[a.to_s].nil?
      end

      true
    end

    def soft_errors
      errors = {}
      self.soft_attributes.each do |a|
        if self.attributes[a.to_s].nil?
          errors[a] = "shouldn't be blank"
        end
      end

      errors
    end

    def progress_count
      count = 0

      self.soft_attributes.each do |a|
        if !self.attributes[a.to_s].nil?
          count += 1
        end
      end

      count
    end

    def progress_percent
      self.progress_count.to_f / self.progress_complete_count.to_f
    end<commit_msg>Use shorter Ruby idioms<commit_after>require 'active_record'
require 'pry'

module SoftValidate

  def self.included(base)
    base.send :extend, ClassMethods
  end

  module ClassMethods
    # any method placed here will apply to classes, like Hickwall

    def soft_validates_presence_of(attr)
      cattr_accessor :soft_attributes
      self.soft_attributes ||= Array.new
      self.soft_attributes << attr
      send :include, InstanceMethods
    end

  end

  module InstanceMethods
    # any method placed here will apply to instaces, like @hickwall

    def progress_complete_count
      self.soft_attributes.length
    end

    def soft_valid?
      self.soft_attributes.all? { |a| !self.attributes[a.to_s].nil? }
    end

    def soft_errors
      Hash[ self.soft_attributes.map { |a| [a, "shouldn't be blank"] if self.attributes[a.to_s].nil? } ]
    end

    def progress_count
      self.soft_attributes.count { |a| !self.attributes[a.to_s].nil? }
    end

    def progress_percent
      self.progress_count.to_f / self.progress_complete_count.to_f
    end
{'fraction_non_alphanumeric': 0.07191780821917808, 'fraction_numerical': 0.0008561643835616438, 'mean_word_length': 2.5516717325227964, 'pattern_counts': {'":': 0, '<': 7, '<?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': '7207970', 'n_tokens_mistral': 740, 'n_tokens_neox': 715, 'n_words': 185}