Method: MotionSupport::Inflector#humanize

Defined in:
motion/inflector/methods.rb

#humanize(lower_case_and_underscored_word) ⇒ Object

Capitalizes the first word and turns underscores into spaces and strips a trailing “_id”, if any. Like titleize, this is meant for creating pretty output.

'employee_salary'.humanize # => "Employee salary"
'author_id'.humanize       # => "Author"


86
87
88
89
90
91
92
93
94
# File 'motion/inflector/methods.rb', line 86

def humanize(lower_case_and_underscored_word)
  result = lower_case_and_underscored_word.to_s.dup
  inflections.humans.each { |(rule, replacement)| break if result.sub!(rule, replacement) }
  result.gsub!(/_id$/, "")
  result.tr!('_', ' ')
  result.gsub(/([a-z\d]*)/i) { |match|
    "#{inflections.acronyms[match] || match.downcase}"
  }.gsub(/^\w/) { $&.upcase }
end