Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/nando/migrator.rb
Instance Method Summary collapse
-
#camelize(uppercase_first_letter = true) ⇒ Object
used to convert to camel or Pascal case (Rails).
-
#demodulize ⇒ Object
gets the class/module name with the previous class/module names.
-
#to_b ⇒ Object
converts a string to boolean.
-
#underscore ⇒ Object
used to convert to snake case (Rails).
Instance Method Details
#camelize(uppercase_first_letter = true) ⇒ Object
used to convert to camel or Pascal case (Rails)
359 360 361 362 363 364 365 366 367 |
# File 'lib/nando/migrator.rb', line 359 def camelize (uppercase_first_letter = true) string = self if uppercase_first_letter string = string.sub(/^[a-z\d]*/) { |match| match.capitalize } else string = string.sub(/^(?:(?=\b|[A-Z_])|\w)/) { |match| match.downcase } end string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub("/", "::") end |
#demodulize ⇒ Object
gets the class/module name with the previous class/module names
370 371 372 |
# File 'lib/nando/migrator.rb', line 370 def demodulize self.split('::').last end |
#to_b ⇒ Object
converts a string to boolean
375 376 377 378 379 380 381 382 383 384 |
# File 'lib/nando/migrator.rb', line 375 def to_b case self.downcase.strip when 'true', 'yes', 'on', 't', '1', 'y', '==' return true when 'nil', 'null' return nil else return false end end |
#underscore ⇒ Object
used to convert to snake case (Rails)
350 351 352 353 354 355 356 |
# File 'lib/nando/migrator.rb', line 350 def underscore self.gsub(/::/, '/') .gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2') .gsub(/([a-z\d])([A-Z])/,'\1_\2') .tr("-", "_") .downcase end |