class String
Constants
- ID_REGEX
- MODULE_SEPARATOR
- SNAKE_CASE_REGEX
- URL_REGEX
- UUID_REGEX
Public Instance Methods
blank?()
click to toggle source
# File lib/stbaldricks/patches/string.rb, line 33 def blank? strip.empty? end
camel_case()
click to toggle source
# File lib/stbaldricks/patches/string.rb, line 10 def camel_case x = split('_').map do |e| case e when 'id', 'uuid', 'url' e.upcase else # capitalize first character (capitalize will lowercase the rest of the word) e[0] = e[0].capitalize e end end x.join end
deconstantize()
click to toggle source
# File lib/stbaldricks/patches/string.rb, line 37 def deconstantize rpartition(MODULE_SEPARATOR).first end
demodulize()
click to toggle source
# File lib/stbaldricks/patches/string.rb, line 41 def demodulize rpartition(MODULE_SEPARATOR).last end
snake_case()
click to toggle source
# File lib/stbaldricks/patches/string.rb, line 27 def snake_case gsub(SNAKE_CASE_REGEX) do (Regexp.last_match[1] ? "_#{Regexp.last_match[1]}" : Regexp.last_match[2]).downcase end.sub(ID_REGEX, '_id').sub(UUID_REGEX, '_uuid').sub(URL_REGEX, '_url') end
to_b()
click to toggle source
# File lib/stbaldricks/patches/string.rb, line 51 def to_b return false if self == 'false' || self == '0' return true if self == 'true' || self == '1' nil end
to_class()
click to toggle source
# File lib/stbaldricks/patches/string.rb, line 45 def to_class split(MODULE_SEPARATOR).reduce(Object) { |a, e| a.const_get(e.to_sym) } rescue nil end