Module: HocusPocus::MiddlewareUtil
- Included in:
- Middleware
- Defined in:
- lib/hocus_pocus/middleware_util.rb
Instance Method Summary collapse
Instance Method Details
#insert_text(body, position, pattern, new_text) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/hocus_pocus/middleware_util.rb', line 3 def insert_text(body, position, pattern, new_text) index = case pattern when Regexp if match = body.match(pattern) match.offset(0)[position == :before ? 0 : 1] else body.size end else pattern end body.insert index, new_text end |