From 81607e68c4036272786b27dced98bf70801154e0 Mon Sep 17 00:00:00 2001 From: Donovan Daniels Date: Tue, 8 Oct 2024 07:42:10 -0500 Subject: [PATCH] Add string extension --- config/initializers/string_extension.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/config/initializers/string_extension.rb b/config/initializers/string_extension.rb index 2c307d6..2b3784d 100644 --- a/config/initializers/string_extension.rb +++ b/config/initializers/string_extension.rb @@ -1,6 +1,18 @@ # frozen_string_literal: true class String + def to_escaped_for_sql_like + gsub(/%|_|\*|\\\*|\\\\|\\/) do |str| + case str + when "%" then '\%' + when "_" then '\_' + when "*" then "%" + when '\*' then "*" + when "\\\\", "\\" then "\\\\" + end + end + end + def truthy? match?(/\A(true|t|yes|y|on|1)\z/i) end