Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/zan_tools/string.rb
Instance Method Summary collapse
- #lower_camel ⇒ Object
- #to_jdbc ⇒ Object
- #underscore ⇒ Object
- #upper_camel ⇒ Object
- #valid_type? ⇒ Boolean
Instance Method Details
#lower_camel ⇒ Object
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_jdbc ⇒ Object
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 |
#underscore ⇒ Object
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_camel ⇒ Object
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
24 25 26 |
# File 'lib/zan_tools/string.rb', line 24 def valid_type? %w{Long String Integer Date}.include?(camel) end |