Sha256: 32ecf51f80a6799766b7093aa73bdfecdf936d3965d5862a89bdcc7907dc3d95

Contents?: true

Size: 557 Bytes

Versions: 6

Compression:

Stored size: 557 Bytes

Contents

# add the underscore from rails for snake_casing strings

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

  def snake_case
    self.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)
    raise ArgumentError.new("invalid value for Boolean: \"#{self}\"")
  end
end
                     

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
openstudio-analysis-0.1.16 lib/openstudio/helpers/string.rb
openstudio-analysis-0.1.15 lib/openstudio/helpers/string.rb
openstudio-analysis-0.1.14 lib/openstudio/helpers/string.rb
openstudio-analysis-0.1.13 lib/openstudio/helpers/string.rb
openstudio-analysis-0.1.12 lib/openstudio/helpers/string.rb
openstudio-analysis-0.1.11 lib/openstudio/helpers/string.rb