Sha256: 5ea1978d41ddc9d49d6246f12f90c5417e173dae5a49aeec6ccaf79c1a058470
Contents?: true
Size: 927 Bytes
Versions: 5
Compression:
Stored size: 927 Bytes
Contents
# frozen_string_literal: true # String helpers class ::String def bool_to_symbol case self when /NOT/ :not when /AND/ :and else :or end end def date? match(/^\d{4}-\d{2}-\d{2}/) ? true : false end def time? match(/ \d{1,2}(:\d\d)? *([ap]m)?/i) end def to_date Chronic.parse(self) end def strip_time sub(/ \d{1,2}(:\d\d)? *([ap]m)?/i, '') end def to_day(time = :end) t = time == :end ? '23:59' : '00:00' Chronic.parse("#{self.strip_time} #{t}") end def number? to_f > 0 end def bool? match(/^(?:y(?:es)?|no?|t(?:rue)?|f(?:alse)?)$/) ? true : false end def to_bool! replace to_bool end ## ## Returns a bool representation of the string. ## ## @return [Boolean] Bool representation of the object. ## def to_bool case self when /^[yt]/i true else false end end end
Version data entries
5 entries across 5 versions & 1 rubygems