<commit_before>class Grammar

  def initialize(random_generator = RandomGenerator.new)
    @rules = {}
    @random_generator = random_generator
  end
  
  def rule(name, &action)
    @rules[name] ||= Rule.new    
    @rules[name] << Production.new(&action)
  end

  def rules_names
    @rules.keys
  end

  def produce(rule)
    raise GrammarError.new("Rule '#{rule}' doesn't exist in the grammar.") unless rules_names.include?(rule)

    @rules[rule].select_production(@random_generator).evaluate(self)
  end

end<commit_msg>Extracting method to find rule by name<commit_after>class Grammar

  def initialize(random_generator = RandomGenerator.new)
    @rules = {}
    @random_generator = random_generator
  end
  
  def rule(name, &action)
    @rules[name] ||= Rule.new    
    @rules[name] << Production.new(&action)
  end

  def rules_names
    @rules.keys
  end

  def produce(rule_name)
    raise GrammarError.new("Rule '#{rule_name}' doesn't exist in the grammar.") unless rules_names.include?(rule_name)

    rule_for(rule_name).select_production(@random_generator).evaluate(self)
  end

 private

  def rule_for(name)
    @rules[name]
  end

end
{'fraction_non_alphanumeric': 0.11265164644714037, 'fraction_numerical': 0.0, 'mean_word_length': 3.9148936170212765, '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': '2849501', 'n_tokens_mistral': 380, 'n_tokens_neox': 365, 'n_words': 82}