Skip to content

Instantly share code, notes, and snippets.

@vshvedov
Created August 22, 2013 15:01
Show Gist options
  • Save vshvedov/6308352 to your computer and use it in GitHub Desktop.
Save vshvedov/6308352 to your computer and use it in GitHub Desktop.
def humanize (value, options = {})
if options.empty?
options[:format] = :sentence
end
values = []
if value.include? '_'
values = value.split('_')
values.each_index do |index|
values[index].downcase!
end
if options[:format] == :allcaps
values.each do |value|
value.capitalize!
end
if options.empty?
options[:seperator] = " "
end
return values.join " "
end
if options[:format] == :class
values.each do |value|
value.capitalize!
end
return values.join ""
end
if options[:format] == :sentence
values[0].capitalize!
return values.join " "
end
if options[:format] == :nocaps
return values.join " "
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment