Module: Casing::Pascal::String

Defined in:
lib/casing/pascal/string.rb

Class Method Summary collapse

Class Method Details

.call(val, include_values: nil, symbol_to_string: nil) ⇒ Object Also known as: !



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/casing/pascal/string.rb', line 4

def self.call(val, include_values: nil, symbol_to_string: nil)
  include_values = include_values.nil? ? true : include_values
  symbol_to_string ||= false

  return val unless include_values

  sym = val.is_a?(Symbol)

  converted = val
    .to_s
    .gsub(/\/(.?)/) { "::" + $1.upcase }
    .gsub(/(^|_)(.)/) { $2.upcase }

  if !symbol_to_string && sym
    converted = converted.to_sym
  end

  converted
end