<commit_before>require 'pathname'

module DruidTools
  class Druid
    attr_accessor :druid, :base
    
    class << self
      attr_accessor :prefix
      
      def pattern
        /\A(?:#{self.prefix}:)?([a-z]{2})(\d{3})([a-z]{2})(\d{4})\z/
      end

      def valid?(druid)
        return druid =~ pattern ? true : false
      end

    end
    self.prefix = 'druid'
    
    [:content, :metadata, :temp].each do |dir_type|
      self.class_eval <<-EOC
        def #{dir_type}_dir(create=true)
          path("#{dir_type}",create)
        end
        
        def find_#{dir_type}(path)
          find(:#{dir_type},path)
        end
      EOC
    end
    
    def initialize(druid,base='.')
      if druid !~ self.class.pattern
        raise ArgumentError, "Invalid DRUID: #{druid}"
      end
      druid = [self.class.prefix,druid].join(':') unless druid =~ /^#{self.class.prefix}:/
      @base = base
      @druid = druid
    end
  
    def id
      @druid.scan(self.class.pattern).flatten.join('')
    end
  
    def tree
      @druid.scan(self.class.pattern).flatten + [id]
    end<commit_msg>Use single ticks to denote druid clearly<commit_after>require 'pathname'

module DruidTools
  class Druid
    attr_accessor :druid, :base
    
    class << self
      attr_accessor :prefix
      
      def pattern
        /\A(?:#{self.prefix}:)?([a-z]{2})(\d{3})([a-z]{2})(\d{4})\z/
      end

      def valid?(druid)
        return druid =~ pattern ? true : false
      end

    end
    self.prefix = 'druid'
    
    [:content, :metadata, :temp].each do |dir_type|
      self.class_eval <<-EOC
        def #{dir_type}_dir(create=true)
          path("#{dir_type}",create)
        end
        
        def find_#{dir_type}(path)
          find(:#{dir_type},path)
        end
      EOC
    end
    
    def initialize(druid,base='.')
      if druid !~ self.class.pattern
        raise ArgumentError, "Invalid DRUID: '#{druid}'"
      end
      druid = [self.class.prefix,druid].join(':') unless druid =~ /^#{self.class.prefix}:/
      @base = base
      @druid = druid
    end
  
    def id
      @druid.scan(self.class.pattern).flatten.join('')
    end
  
    def tree
      @druid.scan(self.class.pattern).flatten + [id]
    end
{'fraction_non_alphanumeric': 0.1506051098162259, 'fraction_numerical': 0.003585835948005379, 'mean_word_length': 2.0121457489878543, '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': '4977199', 'n_tokens_mistral': 779, 'n_tokens_neox': 799, 'n_words': 155}