class CodeCaser::CamelConverter

Public Instance Methods

convert_string(str) click to toggle source
# File lib/code_caser/converters.rb, line 41
def convert_string(str)
  match = false
  output = str.reverse.gsub(/([a-z]+[A-Z]\B)(.)(?!\w*[A-Z]\b)/) { |s|
    match = true
    ($1.to_s + '_' + $2.to_s)
  }.gsub(/([A-Z])([a-z0-9])(?!\w*[A-Z]\b)/) { |s|
    match = true
    ($1.to_s + '_' + $2.to_s)
  }.reverse
  match ? output.downcase : output
end
description() click to toggle source
# File lib/code_caser/converters.rb, line 53
def description
  "camelCase to snake_case"
end