Method: Brick.namify
- Defined in:
- lib/brick.rb
.namify(name, action = nil) ⇒ Object
Convert spaces to underscores if the second character and onwards is mixed case
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/brick.rb', line 177 def namify(name, action = nil) has_uppers = name =~ /[A-Z]+/ has_lowers = name =~ /[a-z]+/ name.downcase! if has_uppers && action == :downcase if name.include?(' ') # All uppers or all lowers? if !has_uppers || !has_lowers name.titleize.tr(' ', '_') else # Mixed uppers and lowers -- just remove existing spaces name.tr(' ', '') end else action == :underscore ? name.underscore : name end end |