<commit_before>module Henshin
  
  class Archive
    
    attr_accessor :config
    
    def initialize( site )
      @archive = Hash.new {|h, k| h[k] = Hash.new {|h, k| h[k] = Hash.new {|h, k| h[k] = []} }}
      @site = site
      @config = site.config
    end
  
    def add_post( post )
      date = post.date
      @archive[date.year.to_s][date.month.to_s][date.day.to_s] << post.to_hash
    end
    
    # Turns the whole archive into a hash. Probably the least efficient thing in the world, but it works
    def to_hash
      if @hashed
        @hashed
      else
        @hashed = Hash.new do |h, k| 
          h[k] = Hash.new do |h, k| # years
            if k == 'posts'
              h[k] = []
            else
              h[k] = Hash.new do |h, k| # months
                if k == 'posts'
                  h[k] = []
                else
                  h[k] = Hash.new do |h, k| # days
                    if k == 'posts'
                      h[k] = []
                    else
                      h[k] = {}
                    end
                  end # /days
                end
              end # /months
            end
          end # /years
        end 
        @archive.each do |y, month|
          month.each do |m, date|
            date.each do |d, p|            
              @hashed[y]['posts'] << p
              @hashed[y][m]['posts'] << p
              @hashed[y][m][d]['posts'] << p
              
              @hashed[y]['posts'].flatten!
              @hashed[y][m]['posts'].flatten!
              @hashed[y][m][d]['posts'].flatten!
            end
          end
        end
        
      end
    end
    
    # Creates a hash with posts separated by year, month then date
    def to_date_hash
      r = Hash.new {|h, k| h[k] = Hash.new {|h, k| h[k] = Hash.new {|h, k| h[k] = []} }}
      @archive.each do |year, m|
        m.each do |month, d|
          d.each do |date, p|
            r[year][month][date] << p
            r[year][month][date].flatten!
          end
        end
      end
      r
    end
    
    # Creates a hash with posts separated by year then month
    def to_month_hash
      r = Hash.new {|h, k| h[k] = Hash.new {|h, k| h[k] = []} }
      @archive.each do |year, m|<commit_msg>Made sure the hash is returned from Archive#to_hash<commit_after>module Henshin
  
  class Archive
    
    attr_accessor :config
    
    def initialize( site )
      @archive = Hash.new {|h, k| h[k] = Hash.new {|h, k| h[k] = Hash.new {|h, k| h[k] = []} }}
      @site = site
      @config = site.config
    end
  
    def add_post( post )
      date = post.date
      @archive[date.year.to_s][date.month.to_s][date.day.to_s] << post.to_hash
    end
    
    # Turns the whole archive into a hash. Probably the least efficient thing in the world, but it works
    def to_hash
      if @hashed
        @hashed
      else
        @hashed = Hash.new do |h, k| 
          h[k] = Hash.new do |h, k| # years
            if k == 'posts'
              h[k] = []
            else
              h[k] = Hash.new do |h, k| # months
                if k == 'posts'
                  h[k] = []
                else
                  h[k] = Hash.new do |h, k| # days
                    if k == 'posts'
                      h[k] = []
                    else
                      h[k] = {}
                    end
                  end # /days
                end
              end # /months
            end
          end # /years
        end 
        @archive.each do |y, month|
          month.each do |m, date|
            date.each do |d, p|            
              @hashed[y]['posts'] << p
              @hashed[y][m]['posts'] << p
              @hashed[y][m][d]['posts'] << p
              
              @hashed[y]['posts'].flatten!
              @hashed[y][m]['posts'].flatten!
              @hashed[y][m][d]['posts'].flatten!
            end
          end
        end
      @hashed
      end
    end
    
    # Creates a hash with posts separated by year, month then date
    def to_date_hash
      r = Hash.new {|h, k| h[k] = Hash.new {|h, k| h[k] = Hash.new {|h, k| h[k] = []} }}
      @archive.each do |year, m|
        m.each do |month, d|
          d.each do |date, p|
            r[year][month][date] << p
            r[year][month][date].flatten!
          end
        end
      end
      r
    end
    
    # Creates a hash with posts separated by year then month
    def to_month_hash
      r = Hash.new {|h, k| h[k] = Hash.new {|h, k| h[k] = []} }
      @archive.each do |year, m|
{'fraction_non_alphanumeric': 0.1336273428886439, 'fraction_numerical': 0.0, 'mean_word_length': 1.1955469506292353, 'pattern_counts': {'":': 0, '<': 23, '<?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': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '199732', 'n_tokens_mistral': 1507, 'n_tokens_neox': 1471, 'n_words': 417}