Class: Aws::Lex::Conversation::Support::Inflector
- Inherits:
-
Object
- Object
- Aws::Lex::Conversation::Support::Inflector
- Defined in:
- lib/aws/lex/conversation/support/inflector.rb
Instance Attribute Summary collapse
-
#input ⇒ Object
Returns the value of attribute input.
Instance Method Summary collapse
-
#initialize(input) ⇒ Inflector
constructor
A new instance of Inflector.
- #to_camel_case(style = :lower) ⇒ Object
- #to_snake_case ⇒ Object
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
#input ⇒ Object
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_case ⇒ Object
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 |