Class: String
- Inherits:
-
Object
- Object
- String
- Includes:
- Term::ANSIColor
- Defined in:
- lib/cfnguardian/string.rb
Instance Method Summary collapse
- #to_camelcase ⇒ Object
- #to_heading ⇒ Object
- #to_resource_name ⇒ Object
- #to_underscore ⇒ Object
- #word_wrap(with = 100) ⇒ Object
Instance Method Details
#to_camelcase ⇒ Object
12 13 14 |
# File 'lib/cfnguardian/string.rb', line 12 def to_camelcase self.split('_').collect(&:capitalize).join end |
#to_heading ⇒ Object
22 23 24 |
# File 'lib/cfnguardian/string.rb', line 22 def to_heading self.split('_').collect(&:capitalize).join(' ') end |
#to_resource_name ⇒ Object
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_underscore ⇒ Object
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 |