Sha256: dac210cb4bac40153c9b1e24bdd0ff7ca41b405f07f5949ef15c3efc4844cd43
Contents?: true
Size: 1.56 KB
Versions: 5
Compression:
Stored size: 1.56 KB
Contents
# frozen_string_literal: true require_relative '../transformer' module Epuber class Transformer class TextTransformer < Transformer # @return [String] # attr_accessor :text # @return [String] # attr_accessor :file_path # @param [String] file_path path to transforming file # @param [String] text text file content # @param [CompilationContext] compilation_context # # @return [String] new transformed text # def call(file_path, text, compilation_context) @file_path = file_path @text = text.dup @block.call(self, @text, compilation_context) new_text = @text @text = nil @file_path = nil new_text end # Shortcut for performing substitutions in text # # @param [Regexp, String] pattern # @param [String, nil] replacement # @param [Bool] multiple_times run the replacement multiple times, while there is something to replace # @param [Proc] block optional block for creating replacements, see String#gsub! # # @return [String, nil] see String#gsub! # def replace_all(pattern, replacement = nil, multiple_times: false, &block) result = if replacement.nil? @text.gsub!(pattern, &block) else @text.gsub!(pattern, replacement, &block) end result = replace_all(pattern, replacement, multiple_times: multiple_times, &block) if multiple_times && !result.nil? result end end end end
Version data entries
5 entries across 5 versions & 1 rubygems