Class: String

Inherits:
Object
  • Object
show all
Includes:
Term::ANSIColor
Defined in:
lib/cfnguardian/string.rb

Instance Method Summary collapse

Instance Method Details

#to_camelcaseObject



12
13
14
# File 'lib/cfnguardian/string.rb', line 12

def to_camelcase
  self.split('_').collect(&:capitalize).join
end

#to_headingObject



22
23
24
# File 'lib/cfnguardian/string.rb', line 22

def to_heading
  self.split('_').collect(&:capitalize).join(' ')
end

#to_resource_nameObject



16
17
18
19
20
# File 'lib/cfnguardian/string.rb', line 16

def to_resource_name
  self.split(/(\.|-|_)/).
  map(&:capitalize).join.
  gsub(/[^0-9A-Za-z]/, '')
end

#to_underscoreObject



4
5
6
7
8
9
10
# File 'lib/cfnguardian/string.rb', line 4

def to_underscore
  self.gsub(/::/, '/').
  gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
  gsub(/([a-z\d])([A-Z])/,'\1_\2').
  tr("-", "_").
  downcase
end

#word_wrap(with = 100) ⇒ Object



26
27
28
29
30
# File 'lib/cfnguardian/string.rb', line 26

def word_wrap(with=100)
  self.scan(/\S.{0,#{with}}\S(?=\s|$)|\S+/).
  map {|line| line + "\n"}.
  join('')
end