Module: AWS::Core::Inflection

Included in:
OptionGrammar::ModuleMethods
Defined in:
lib/aws/core/inflection.rb

Class Method Summary collapse

Class Method Details

.class_name(name) ⇒ Object


39
40
41
42
# File 'lib/aws/core/inflection.rb', line 39

def class_name(name)
  name.sub(/^(.)/) { |m| m.upcase }.
    gsub(/[-_]([a-z])/i) { |m| m[1,1].upcase }
end

.ruby_name(aws_name) ⇒ Object


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/aws/core/inflection.rb', line 20

def ruby_name(aws_name)

  #aws_name.sub(/^.*:/, '').
  #  gsub(/[A-Z]+[a-z]+/){|str| "_#{str.downcase}_" }.
  #  gsub(/(^_|_$)/, '').
  #  gsub(/__/, '_').
  #  downcase

  return 'etag' if aws_name == 'ETag'

  aws_name.
    sub(/^.*:/, '').                          # strip namespace
    gsub(/([A-Z0-9]+)([A-Z][a-z])/, '\1_\2'). # split acronyms from words
    scan(/[a-z]+|\d+|[A-Z0-9]+[a-z]*/).       # split remaining words
    join('_').downcase                        # join parts _ and downcase

end