Created
August 22, 2013 15:01
-
-
Save vshvedov/6308352 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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