lib/code_kindly/utils/boolean.rb in codekindly-utils-0.0.5 vs lib/code_kindly/utils/boolean.rb in codekindly-utils-0.0.6
- old
+ new
@@ -1,32 +1,48 @@
+# frozen_string_literal: true
+
module CodeKindly
module Utils
class Boolean
+ include Deprecation
+
# modified from ActiveRecord::ConnectionAdapters::Column (4.2.9)
- TRUE_VALUES = [true, 1, "1", "t", "T", "true", "TRUE", "on", "ON", "y", "yes"]
- FALSE_VALUES = [false, 0, "0", "f", "F", "false", "FALSE", "off", "OFF", "n", "no"]
+ TRUES = [true, 1, '1', 't', 'true', 'on', 'y', 'yes']
+ .map(&:freeze).freeze
+ FALSES = [false, 0, '0', 'f', 'false', 'off', 'n', 'no']
+ .map(&:freeze).freeze
class << self
- def from (value)
- return true if is_true?(value)
- return false if is_false?(value)
+ def from(value)
+ return true if true?(value)
+ return false if false?(value)
nil
end
- def is_false? (value)
- return true if FALSE_VALUES.include?(value)
+ def false?(value)
+ return true if FALSES.include?(value)
if value.respond_to?(:downcase)
- return true if FALSE_VALUES.include?(value.downcase)
+ return true if FALSES.include?(value.downcase)
end
false
end
- def is_true? (value)
- return true if TRUE_VALUES.include?(value)
+ def true?(value)
+ return true if TRUES.include?(value)
if value.respond_to?(:downcase)
- return true if TRUE_VALUES.include?(value.downcase)
+ return true if TRUES.include?(value.downcase)
end
false
+ end
+
+ def is_false?(value)
+ deprecate :is_false?, :false?, :'0.1.0'
+ false?(value)
+ end
+
+ def is_true?(value)
+ deprecate :is_true?, :true?, :'0.1.0'
+ true?(value)
end
end
end
end
end