<commit_before>module Hologram
  class DocumentBlock
    COMMENT_REGEX = /^\s*---\s(.*?)\s---$/m

    attr_accessor :name, :parent, :children, :title, :category, :markdown, :config, :heading, :errors

    def initialize(config = nil, markdown = nil)
      @children = {}
      @errors = []
      set_members(config, markdown) if config and markdown
    end

    def self.from_comment(comment)
      comment_match = COMMENT_REGEX.match(comment)
      return if !comment_match

      markdown = comment.sub(comment_match[0], '')
      config = YAML::load(comment_match[1])

      self.new(config, markdown)
    rescue ArgumentError, Psych::SyntaxError
      raise CommentLoadError, "Could not parse comment:\n#{comment}"
    end

    def set_members(config, markdown)
      @name     = config['name']
      @category = config['category']
      @title    = config['title']
      @parent   = config['parent']
      @markdown = markdown
    end

    def get_hash
      {:name => @name,
       :parent => @parent,
       :category => @category,
       :title => @title
      }
    end

    def is_valid?
      errors << 'Missing required category config value' if !category
      errors << 'Missing required name config value' if !name
      errors << 'Missing required markdown' if !markdown
      errors.empty?
    end<commit_msg>Default name to title with underscores and update is_valid<commit_after>module Hologram
  class DocumentBlock
    COMMENT_REGEX = /^\s*---\s(.*?)\s---$/m

    attr_accessor :name, :parent, :children, :title, :category, :markdown, :config, :heading, :errors

    def initialize(config = nil, markdown = nil)
      @children = {}
      @errors = []
      set_members(config, markdown) if config and markdown
    end

    def self.from_comment(comment)
      comment_match = COMMENT_REGEX.match(comment)
      return if !comment_match

      markdown = comment.sub(comment_match[0], '')
      config = YAML::load(comment_match[1])

      self.new(config, markdown)
    rescue ArgumentError, Psych::SyntaxError
      raise CommentLoadError, "Could not parse comment:\n#{comment}"
    end

    def set_members(config, markdown)
      @name     = config['name']
      @category = config['category']
      @title    = config['title']
      @parent   = config['parent']
      @markdown = markdown

      if @name.nil?
        @name = @title.gsub(' ', '_')
      end
    end

    def get_hash
      {:name => @name,
       :parent => @parent,
       :category => @category,
       :title => @title
      }
    end

    def is_valid?
      errors << 'Missing required category and/or parent config value' if !category and !parent
      errors << 'Missing name or title config value' if !name and !title
      errors << 'Missing required markdown' if !markdown
      errors.empty?
    end
{'fraction_non_alphanumeric': 0.12236889047449162, 'fraction_numerical': 0.0014270424545130217, 'mean_word_length': 2.679790026246719, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 11, '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': '3372459', 'n_tokens_mistral': 848, 'n_tokens_neox': 821, 'n_words': 227}