Sha256: 84735f3414af672411f13332335ab6d999e4e245a5f4e8275059497d16a93a8c
Contents?: true
Size: 881 Bytes
Versions: 3
Compression:
Stored size: 881 Bytes
Contents
# Copyright (c) 2023 Jerome Arbez-Gindre # frozen_string_literal: true # :nocov: require('asciidoctor/extensions') unless RUBY_ENGINE == 'opal' # :nocov: require('ostruct') module Asciidoctor module DefMastership # Hosts several Text replacement rules class RegexpDispatcher # Class to link a regexp with a method Rule = Struct.new(:regexp, :method_symbol) private_constant :Rule def initialize(effective_subs) @effective_subs = effective_subs @rules = [] end def add_rule(regexp, method_symbol) @rules << Rule.new(regexp, method_symbol) self end def replace(line) @rules.each do |rule| matches = rule.regexp.match(line) return @effective_subs.public_send(rule.method_symbol, line, matches) if matches end [line] end end end end
Version data entries
3 entries across 3 versions & 1 rubygems