Sha256: aadd7e8a06bbf15acaf20a42026205dbb0190e802a6b9158fc295f0d1cdddf00

Contents?: true

Size: 503 Bytes

Versions: 4

Compression:

Stored size: 503 Bytes

Contents

# add the underscore from rails for snake_casing strings

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

  def snake_case
    gsub(' ', '_').downcase
  end

  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
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
openstudio-analysis-0.3.1 lib/openstudio/helpers/string.rb
openstudio-analysis-0.3.0 lib/openstudio/helpers/string.rb
openstudio-analysis-0.2.3 lib/openstudio/helpers/string.rb
openstudio-analysis-0.2.2 lib/openstudio/helpers/string.rb