Sha256: 91e8bea3db5f722b692080fe965921724178690b2c0aa25bf9eff87a5bc395c0
Contents?: true
Size: 579 Bytes
Versions: 5
Compression:
Stored size: 579 Bytes
Contents
class StringCase def self.capitalize(string) "#{string[0].upcase}#{string[1..-1]}" end def self.snake_to_capitalized_spaced(snake_case_string, exclude: '', transform: ->(item) { StringCase.capitalize(item) }) # Split by underscores, then apply the transformation to each part parts = snake_case_string.split('_').map do |item| # Return the item as-is if it matches the exclude value item == exclude ? item : transform.call(item) end # Join the parts with a space parts.join(' ') end end
Version data entries
5 entries across 5 versions & 1 rubygems