module SQLite3ExtendFunction::Functions::Initcap

SQLite3ExtendFunction::Functions::Initcap

Public Class Methods

call(str) click to toggle source

@param [String] str @return [String] @raise [SQLite3::SQLException]

# File lib/sqlite3_extend_function/functions/initcap.rb, line 11
def call(str)
  return if str.nil?

  str.split(/([a-zA-Z0-9]*|[^a-zA-Z0-9]*)/).map.with_index do |s, i|
    i.odd? ? s.downcase.capitalize : s
  end.join
rescue StandardError
  raise SQLite3::SQLException, 'No function matches the given name and argument types. ' \
    'You might need to add explicit type casts.'
end