eBooru/config/initializers/core_extensions.rb

35 lines
672 B
Ruby
Raw Normal View History

# frozen_string_literal: true
2010-08-18 18:42:33 -04:00
module Danbooru
module Extensions
module String
def to_escaped_for_sql_like
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
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