Sha256: 3c6991dc11300db5f4b019c9658f16f47f7e454486b25ecffca4f5168d38b708
Contents?: true
Size: 817 Bytes
Versions: 24
Compression:
Stored size: 817 Bytes
Contents
class Object def blank? respond_to?(:empty?) ? empty? : !self end def present? !blank? end def boolean? [true, false].include? self end end class String def to_bool return true if self == true || self =~ (/(true|t|yes|y|x|1)$/i) return false if self == false || self.blank? || self =~ (/(false|f|no|n|0)$/i) raise ArgumentError.new("invalid value for Boolean: \"#{self}\"") end def string_between(marker1, marker2) self[/#{Regexp.escape(marker1)}(.*?)#{Regexp.escape(marker2)}/m, 1] end def format_date_time(date_time_format) return if self.blank? new_date = DateTime.parse(self) if ENV['LOCALE'] && date_time_format.is_a?(Symbol) I18n.l(new_date, format: date_time_format) else new_date.strftime(date_time_format) end end end
Version data entries
24 entries across 24 versions & 1 rubygems