class Jekyll::Antex::Stasher
Attributes
matchers[R]
Public Class Methods
new(matchers)
click to toggle source
# File lib/jekyll/antex/stasher.rb, line 10 def initialize(matchers) @stash = [] @matchers = matchers @matchers.sort_by!(&:priority) @matchers.reverse! end
Public Instance Methods
bake() { |match, matcher| ... }
click to toggle source
# File lib/jekyll/antex/stasher.rb, line 27 def bake @stash.map! do |uuid, match, matcher| replacement = yield match, matcher [uuid, match, matcher, replacement] end end
drop(input)
click to toggle source
# File lib/jekyll/antex/stasher.rb, line 34 def drop(input) input.dup.tap do |output| @stash.each do |uuid, match, _, replacement| output.gsub!(uuid) { replacement || match.to_s } end end end
lift(input)
click to toggle source
# File lib/jekyll/antex/stasher.rb, line 17 def lift(input) input.dup.tap do |output| @matchers.each do |matcher| output.gsub!(matcher.regexp) do store(Regexp.last_match, matcher) end end end end
Private Instance Methods
store(match, matcher)
click to toggle source
# File lib/jekyll/antex/stasher.rb, line 44 def store(match, matcher) SecureRandom.uuid.tap do |uuid| @stash.push([uuid, match, matcher, nil]) end end