Sha256: 2332a1ecc87cb1a9cc9b29179d674cfc5aea68cc4c2fee97b47f4ed8a715999b
Contents?: true
Size: 640 Bytes
Versions: 53
Compression:
Stored size: 640 Bytes
Contents
class Object def blank? respond_to?(:empty?) ? empty? : !self end def present? !blank? 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) new_date.strftime(date_time_format) end end
Version data entries
53 entries across 53 versions & 2 rubygems