2024-05-03 03:04:43 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class String
|
2024-10-08 12:42:10 +00:00
|
|
|
def to_escaped_for_sql_like
|
|
|
|
gsub(/%|_|\*|\\\*|\\\\|\\/) do |str|
|
|
|
|
case str
|
|
|
|
when "%" then '\%'
|
|
|
|
when "_" then '\_'
|
|
|
|
when "*" then "%"
|
|
|
|
when '\*' then "*"
|
|
|
|
when "\\\\", "\\" then "\\\\"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-05-03 03:04:43 +00:00
|
|
|
def truthy?
|
|
|
|
match?(/\A(true|t|yes|y|on|1)\z/i)
|
|
|
|
end
|
|
|
|
|
|
|
|
def falsy?
|
|
|
|
match?(/\A(false|f|no|n|off|0)\z/i)
|
|
|
|
end
|
|
|
|
end
|