Sha256: cb36bdb44ca9947db2553f39f65c2109ba0834b490eb9622c46779579dc16e3e
Contents?: true
Size: 1.1 KB
Versions: 2
Compression:
Stored size: 1.1 KB
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? dup.force_encoding("utf-8").match?(/^\d{4}-\d{2}-\d{2}/) end def time? dup.force_encoding("utf-8").match(/ \d{1,2}(:\d\d)? *([ap]m)?/i) end def to_date Chronic.parse(dup.force_encoding("utf-8")) end def strip_time dup.force_encoding("utf-8").sub(/ \d{1,2}(:\d\d)? *([ap]m)?/i, "") end def to_day(time = :end) t = time == :end ? "23:59" : "00:00" Chronic.parse("#{strip_time} #{t}") end def number? to_f.positive? end def bool? dup.force_encoding("utf-8").match?(/^(?:y(?:es)?|no?|t(?:rue)?|f(?:alse)?)$/) end def meta? self =~ /^---/m end def yaml? self =~ /^\w+: +\S+/m 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
marked-conductor-1.0.9 | lib/conductor/string.rb |
marked-conductor-1.0.8 | lib/conductor/string.rb |