Class: String

Inherits:
Object
  • Object
show all
Includes:
GClouder::Shell
Defined in:
lib/gclouder/monkey_patches/string.rb

Instance Method Summary collapse

Methods included from GClouder::Shell

included, #shell

Methods included from GClouder::Logging

#add, #bad, #change, #debug, #error, #fatal, #good, included, #info, log, loggers, #remove, report, #resource_state, setup, #warn, #warning

Instance Method Details

#mixedcaseObject



14
15
16
# File 'lib/gclouder/monkey_patches/string.rb', line 14

def mixedcase
  self.split('_').collect(&:capitalize).join.sub(/^[A-Z]/, &:downcase)
end

#snakecaseObject



6
7
8
9
10
11
12
# File 'lib/gclouder/monkey_patches/string.rb', line 6

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

#truncate(length = 32) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/gclouder/monkey_patches/string.rb', line 18

def truncate(length = 32)
  raise 'Pleasant: Length should be greater than 3' unless length > 3

  truncated_string = self.to_s

  if truncated_string.length > length
    truncated_string = truncated_string[0...(length - 3)]
    truncated_string += "..."
  end

  truncated_string
end