Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/rspec/cloud/core/ext.rb
Instance Method Summary collapse
- #integer? ⇒ Boolean
- #to_bool ⇒ Object
- #to_camel_back ⇒ Object
- #to_camel_case ⇒ Object
- #to_snake_case ⇒ Object
- #uncapitalize ⇒ Object
Instance Method Details
#integer? ⇒ Boolean
2 3 4 |
# File 'lib/rspec/cloud/core/ext.rb', line 2 def integer? self =~ /\A[-+]?[0-9]+\z/ end |
#to_bool ⇒ Object
28 29 30 31 32 |
# File 'lib/rspec/cloud/core/ext.rb', line 28 def to_bool return false if self =~ (/^(false)$/i) return true if self =~ (/^(true)$/i) fail "invalid value for Boolean: \"#{self}\"" end |
#to_camel_back ⇒ Object
24 25 26 |
# File 'lib/rspec/cloud/core/ext.rb', line 24 def to_camel_back to_camel_case.uncapitalize end |
#to_camel_case ⇒ Object
15 16 17 18 |
# File 'lib/rspec/cloud/core/ext.rb', line 15 def to_camel_case return self if self !~ /_/ && self =~ /[A-Z]+.*/ split('_').map(&:capitalize).join end |
#to_snake_case ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/rspec/cloud/core/ext.rb', line 6 def to_snake_case gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2') .tr('-', '_') .gsub(/\s/, '_') .gsub(/__+/, '_') .downcase end |
#uncapitalize ⇒ Object
20 21 22 |
# File 'lib/rspec/cloud/core/ext.rb', line 20 def uncapitalize self[0, 1].downcase + self[1..-1] end |