Last active
December 10, 2015 11:28
-
-
Save whiteleaf7/bd8cf672b1fab1367ab0 to your computer and use it in GitHub Desktop.
This file contains 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
converter "test_convert_numbers.txt" do | |
def _stash_number_cache(match) | |
@_number_string_cache ||= {} | |
index = convert_numbers(@_number_string_cache.size.to_s) | |
@_number_string_cache[index] = match | |
"[#数字キャッシュ=#{index}]" | |
end | |
def _rebuild_number_cache(io) | |
io.string.gsub!(/[#数字キャッシュ=(.+?)]/) do | |
@_number_string_cache[$1] | |
end | |
end | |
def before(io, type) | |
io.string.gsub!(/[\d.]+/) do |match| | |
if match.match(/\d/) && match.match(/\./) | |
_stash_number_cache(match) | |
else | |
match | |
end | |
end | |
io | |
end | |
def after(io, type) | |
_rebuild_number_cache(io) | |
io | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment