Add substitute_with_block method to TextRun, that can take a block wtih access to MatchData with regex capture groups etc#161
Merged
satoryu merged 1 commit intoruby-docx:masterfrom Sep 11, 2025
Conversation
satoryu
reviewed
May 17, 2025
…ih access to MatchData with regex capture groups etc I needed to do a `substitute` where the match arg was a regex, and if it were gsub I'd be using a block to have access to capture groups in $1 $2 $3 etc. Because of the weird way variables $1 $2 $3 are handled in ruby and block scope, I couldn't provide a delegated block to give exactly the same API as ordinary gsub. My original idea was to do that, added on to existing #substitute. But instead, had to provide a new/alternate #substitute_with_block method, with a block that actually gets a MatchData object as arg, and can access whatever it needs from there, including capture groups and match string.
04d7d19 to
1a51b4e
Compare
Contributor
Author
|
Hm, CI failure is weird and annoying.
Any ideas what would be different on CI? The failed test is NOT my new test, but an existing test... don't understand how this PR could cause it to break... is my new test somehow resulting in deletion of a file? But why wouldn't that reproduce locally? docx/spec/docx/document_spec.rb Lines 515 to 536 in 1a51b4e Any advice? |
Member
|
The CI failure sometimes happens only on GitHub Actions. I reran the tests, and all of them passed. |
Contributor
Author
|
thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I needed to do a
substitutewhere the match arg was a regex, and if it were gsub I'd be using a block to have access to capture groups in $1 $2 $3 etc. Because of the weird way variables $1 $2 $3 are handled in ruby and block scope, I couldn't provide a delegated block to give exactly the same API as ordinary gsub. My original idea was to do that, added on to existing #substitute.But instead, had to provide a new/alternate #substitute_block method, with a block that actually gets a MatchData object as arg, and can access whatever it needs from there, including capture groups and match string.