Sha256: 1e4206d955391c439f61b0f626dc995e72a2eb4132bfaee4f8c3740ef1ed8bbc

Contents?: true

Size: 588 Bytes

Versions: 4

Compression:

Stored size: 588 Bytes

Contents

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

  def lower_camel
    gsub(/\A([A-Z])/){|e| $1.downcase }.gsub(/[_]([a-z])/){|e| $1.upcase}
  end

  def upper_camel
    gsub(/\A(.)/){|e| $1.upcase }.gsub(/[_]([a-z])/){|e| $1.upcase}
  end

  def to_jdbc
    {
      'Long' => 'BIGINT',
      'String' => 'VARCHAR',
      'Date' => 'TIMESTAMP',
      'Integer' => 'INTEGER',
      'Double' => 'DOUBLE'
    }[self] || self.upcase
  end

  def valid_type?
    %w{Long String Integer Date}.include?(camel)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
zan_tools-0.1.3 lib/zan_tools/string.rb
zan_tools-0.1.2 lib/zan_tools/string.rb
zan_tools-0.1.1 lib/zan_tools/string.rb
zan_tools-0.1.0 lib/zan_tools/string.rb