Class: CodeCaser::CamelConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/code_caser/converters.rb

Instance Method Summary collapse

Instance Method Details

#convert_line(str) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/code_caser/converters.rb', line 3

def convert_line(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

#descriptionObject



15
16
17
# File 'lib/code_caser/converters.rb', line 15

def description
  "camelCase to snake_case"
end