Sha256: d60c3f1eefbc6ede7db55bf5c5dc5118407186e1d7a2522f27785c093c4a8553
Contents?: true
Size: 1.08 KB
Versions: 2
Compression:
Stored size: 1.08 KB
Contents
# frozen_string_literal: true require 'yaml' module Diachronr # a set of rules, categories, and rewrites applicable to words class RuleSet attr_accessor :rules, :categories, :rewrites, :options def initialize(rules, categories, rewrites, options = {}) @rules = rules @categories = categories @rewrites = rewrites @options = options end # initialize def self.load(filename) options = YAML.load_file filename rules = options['rules'].map { |a| Diachronr::Rule.new(a) } categories = options['categories'].map { |a| Diachronr::Category.new(a) } rewrites = options['rewrites'].map { |a| Diachronr::Rewrite.new(a) } RuleSet.new rules, categories, rewrites, options end def apply(target) @rewrites.each do |rewrite| target = rewrite.apply target end # each @rules.each do |rule| target = rule.apply target, categories: @categories end # each @rewrites.each do |rewrite| target = rewrite.reverse target end # each target end # apply end # class end # module
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
diachronr-1.1.0 | lib/diachronr/ruleset.rb |
diachronr-1.0.0 | lib/diachronr/ruleset.rb |