Class: Kotoshu::Grammar::RuleLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/kotoshu/grammar/rule_loader.rb

Overview

Loads grammar rules from YAML configuration files.

This class reads rule definitions from YAML files in the dictionaries/language/grammar/ directory.

Instance Method Summary collapse

Constructor Details

#initialize(rules_path) ⇒ RuleLoader

Returns a new instance of RuleLoader.



13
14
15
# File 'lib/kotoshu/grammar/rule_loader.rb', line 13

def initialize(rules_path)
  @rules_path = rules_path
end

Instance Method Details

#load_rulesArray<Rule>

Load all rules from the rules.yaml file.

Returns:

  • (Array<Rule>)

    Array of rule instances



20
21
22
23
24
25
26
27
28
# File 'lib/kotoshu/grammar/rule_loader.rb', line 20

def load_rules
  rules_file = File.join(@rules_path, 'rules.yaml')
  return [] unless File.exist?(rules_file)

  config = YAML.load_file(rules_file)
  return [] unless config && config['rules']

  config['rules'].map { |rule_config| Rule.from_yaml(rule_config) }
end