Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/zan_tools/string.rb

Instance Method Summary collapse

Instance Method Details

#lower_camelObject



6
7
8
# File 'lib/zan_tools/string.rb', line 6

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

#to_jdbcObject



14
15
16
17
18
19
20
21
22
# File 'lib/zan_tools/string.rb', line 14

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

#underscoreObject



2
3
4
# File 'lib/zan_tools/string.rb', line 2

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

#upper_camelObject



10
11
12
# File 'lib/zan_tools/string.rb', line 10

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

#valid_type?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/zan_tools/string.rb', line 24

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