Class: RenderAPI::Camelise
- Inherits:
-
Object
- Object
- RenderAPI::Camelise
- Defined in:
- lib/render_api/camelise.rb
Overview
Borrowed from awrence: github.com/technicalpanda/awrence/blob/main/lib/awrence/methods.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.call ⇒ Object
7 8 9 |
# File 'lib/render_api/camelise.rb', line 7 def self.call(...) new.call(...) end |
Instance Method Details
#call(string, first_upper: false) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/render_api/camelise.rb', line 11 def call(string, first_upper: false) if first_upper string = gsubbed(string, /(?:^|_)([^_\s]+)/) gsubbed(string, %r{/([^/]*)}, "::") else parts = string.split("_", 2) parts[0] << call(parts[1], first_upper: true) if parts.size > 1 parts[0] || "" end end |