2024-02-25 12:15:55 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2010-08-18 18:42:33 -04:00
|
|
|
module Danbooru
|
|
|
|
module Extensions
|
|
|
|
module String
|
|
|
|
def to_escaped_for_sql_like
|
2017-05-22 13:44:36 -04:00
|
|
|
string = self.gsub(/%|_|\*|\\\*|\\\\|\\/) do |str|
|
|
|
|
case str
|
|
|
|
when '%' then '\%'
|
|
|
|
when '_' then '\_'
|
|
|
|
when '*' then '%'
|
|
|
|
when '\*' then '*'
|
|
|
|
when '\\\\' then '\\\\'
|
|
|
|
when '\\' then '\\\\'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
string
|
2010-08-18 18:42:33 -04:00
|
|
|
end
|
|
|
|
|
2018-05-03 19:53:35 -04:00
|
|
|
def truthy?
|
|
|
|
self.match?(/\A(true|t|yes|y|on|1)\z/i)
|
|
|
|
end
|
|
|
|
|
|
|
|
def falsy?
|
|
|
|
self.match?(/\A(false|f|no|n|off|0)\z/i)
|
|
|
|
end
|
2010-02-06 16:48:40 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class String
|
2010-08-18 18:42:33 -04:00
|
|
|
include Danbooru::Extensions::String
|
2010-02-06 16:48:40 -05:00
|
|
|
end
|