Skip to content

Instantly share code, notes, and snippets.

@whiteleaf7
Last active December 10, 2015 11:28
Show Gist options
  • Save whiteleaf7/bd8cf672b1fab1367ab0 to your computer and use it in GitHub Desktop.
Save whiteleaf7/bd8cf672b1fab1367ab0 to your computer and use it in GitHub Desktop.
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