Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/openstudio/helpers/string.rb
Overview
add the underscore from rails for snake_casing strings
Instance Method Summary collapse
Instance Method Details
#snake_case ⇒ Object
12 13 14 |
# File 'lib/openstudio/helpers/string.rb', line 12 def snake_case gsub(' ', '_').downcase end |
#to_bool ⇒ Object
16 17 18 19 20 |
# File 'lib/openstudio/helpers/string.rb', line 16 def to_bool return true if self == true || self =~ (/(true|t|yes|y|1)$/i) return false if self == false || self =~ (/(false|f|no|n|0)$/i) fail "invalid value for Boolean: '#{self}'" end |
#underscore ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/openstudio/helpers/string.rb', line 4 def underscore gsub(/::/, '/') .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2') .tr('-', '_') .downcase end |