Class: Asciidoctor::Defmastership::RegexpDispatcher
- Inherits:
-
Object
- Object
- Asciidoctor::Defmastership::RegexpDispatcher
- Defined in:
- lib/asciidoctor-defmastership/regexp_dispatcher.rb
Overview
Hosts several Text replacement rules
Instance Method Summary collapse
-
#add_rule(regexp, method_symbol) ⇒ RegexpDispatcher
Add a rule.
-
#initialize(client) ⇒ RegexpDispatcher
constructor
A new instance of RegexpDispatcher.
-
#replace(line) ⇒ Array<String>
Add a rule.
Constructor Details
#initialize(client) ⇒ RegexpDispatcher
Returns a new instance of RegexpDispatcher.
19 20 21 22 |
# File 'lib/asciidoctor-defmastership/regexp_dispatcher.rb', line 19 def initialize(client) @client = client @rules = [] end |
Instance Method Details
#add_rule(regexp, method_symbol) ⇒ RegexpDispatcher
Add a rule
29 30 31 32 |
# File 'lib/asciidoctor-defmastership/regexp_dispatcher.rb', line 29 def add_rule(regexp, method_symbol) @rules << Rule.new(regexp, method_symbol) self end |
#replace(line) ⇒ Array<String>
Add a rule
38 39 40 41 42 43 44 |
# File 'lib/asciidoctor-defmastership/regexp_dispatcher.rb', line 38 def replace(line) @rules.each do |rule| matches = rule.regexp.match(line) return @client.public_send(rule.method_symbol, line, matches) if matches end [line] end |