Class: Aws::Lex::Conversation::Support::Inflector

Inherits:
Object
  • Object
show all
Defined in:
lib/aws/lex/conversation/support/inflector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ Inflector

Returns a new instance of Inflector.



10
11
12
# File 'lib/aws/lex/conversation/support/inflector.rb', line 10

def initialize(input)
  self.input = input.to_s
end

Instance Attribute Details

#inputObject

Returns the value of attribute input.



8
9
10
# File 'lib/aws/lex/conversation/support/inflector.rb', line 8

def input
  @input
end

Instance Method Details

#to_camel_case(style = :lower) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/aws/lex/conversation/support/inflector.rb', line 25

def to_camel_case(style = :lower)
  parts = input.split('_')
  first = parts.shift
  rest = parts.map(&:capitalize)

  case style
  when :lower
    rest.unshift(first).join
  when :upper
    rest.unshift(first.capitalize).join
  else
    raise ArgumentError, "invalid option: `#{style.inspect}`"
  end
end

#to_snake_caseObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/aws/lex/conversation/support/inflector.rb', line 14

def to_snake_case
  # shamelessly borrowed from ActiveSupport
  input
    .gsub(/::/, '/')
    .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
    .gsub(/([a-z\d])([A-Z])/, '\1_\2')
    .tr('-', '_')
    .gsub(/\W/, '_')
    .downcase
end