class Siba::StringHelper

Public Class Methods

camelize(str) click to toggle source

Convers a string to CamelCase. Based on Rails ActiveSupport::Inflector.camelize.

# File lib/siba/helpers/string_helper.rb, line 18
def camelize(str)
  str = str.capitalize
  str.gsub(/(?:_|-)([a-z\d]*)/i) { "#{$1.capitalize}" }
end
escape_for_yaml(str) click to toggle source
# File lib/siba/helpers/string_helper.rb, line 23
def escape_for_yaml(str)
  str.gsub("\\","\\\\\\").gsub("\"","\\\"")
end
format_time(time) click to toggle source
# File lib/siba/helpers/string_helper.rb, line 27
def format_time(time)
  time.strftime("%B %e, %Y")
end
nil_or_empty(str) click to toggle source
# File lib/siba/helpers/string_helper.rb, line 13
def nil_or_empty(str)
  str.nil? || str.strip.empty?
end
str_to_alphnumeric(str) click to toggle source

Helps to use a string in URLs and file names by replacing all non-alphanumeric characters with ‘-’ and converting to lowercase

# File lib/siba/helpers/string_helper.rb, line 9
def str_to_alphnumeric(str)
  str.downcase.gsub(/[^ a-z0-9]/,' ').strip.gsub(/ {1,}/,'-')
end