<commit_before>module Hahashie
  class Dash
    class << self
      attr_reader :defaults, :required, :props_class
    end
    attr_reader :props_obj

    def self.property(name, options = {})
      @props_class ||= []
      @defaults ||= {}
      @required ||= {}

      @props_class << name
      @defaults[name] = options[:default]
      @required[name] = true if options[:required]
    end

    def initialize(hash = {})
      @props_obj = {}
      self.class.props_class.each do |name|
        @props_obj[name] = hash[name] ? hash[name] : self.class.defaults[name]
        define_singleton_method name do
          @props_obj[name]
        end

        define_singleton_method("#{name}=") do |value|
          raise ArgumentError if value.nil? && self.class.required.key?(name)
          @props_obj[name] = value
        end

        raise ArgumentError if self.class.required.key?(name) && !@props_obj[name]
      end
    end

    def [](name)
      raise NoMethodError unless @props_obj.has_key?(name)
      @props_obj[name]
    end
  end
end<commit_msg>tiny refact<commit_after>module Hahashie
  class Dash
    class << self
      attr_reader :defaults, :required, :props_class
    end
    attr_reader :props_obj

    def self.property(name, options = {})
      @props_class ||= []
      @defaults ||= {}
      @required ||= {}

      @props_class << name
      @defaults[name] = options[:default]
      @required[name] = true if options[:required]
    end

    def initialize(hash = {})
      @props_obj = {}
      self.class.props_class.each do |name|
        @props_obj[name] = hash[name] ? hash[name] : self.class.defaults[name]

        define_getter name
        define_setter name

        raise ArgumentError if self.class.required.key?(name) && !@props_obj[name]
      end
    end

    def define_getter(name)
      define_singleton_method name do
        @props_obj[name]
      end
    end

    def define_setter(name)
      define_singleton_method("#{name}=") do |value|
        raise ArgumentError if value.nil? && self.class.required.key?(name)
        @props_obj[name] = value
      end
    end

    def [](name)
      raise NoMethodError unless @props_obj.has_key?(name)
      @props_obj[name]
    end
  end
end
{'fraction_non_alphanumeric': 0.11996418979409132, 'fraction_numerical': 0.0, 'mean_word_length': 2.5141509433962264, 'pattern_counts': {'":': 0, '<': 11, '<?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': '4292163', 'n_tokens_mistral': 715, 'n_tokens_neox': 708, 'n_words': 152}