class Epuber::Transformer::TextTransformer
Attributes
file_path[RW]
@return [String]
text[RW]
@return [String]
Public Instance Methods
call(file_path, text, compilation_context)
click to toggle source
@param [String] file_path
path to transforming file @param [String] text text file content @param [CompilationContext] compilation_context
@return [String] new transformed text
# File lib/epuber/transformer/text_transformer.rb, line 23 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
replace_all(pattern, replacement = nil, multiple_times: false, &block)
click to toggle source
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!
# File lib/epuber/transformer/text_transformer.rb, line 46 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 if multiple_times && !result.nil? result = replace_all(pattern, replacement, multiple_times: multiple_times, &block) end result end