Class: String

Inherits:
Object show all
Defined in:
lib/strongspace/helpers.rb,
lib/strongspace/helpers.rb,
lib/strongspace/helpers.rb,
lib/strongspace/helpers.rb,
lib/strongspace/helpers.rb,
lib/strongspace/helpers.rb,
lib/strongspace/helpers.rb,
lib/strongspace/helpers.rb,
lib/strongspace/helpers.rb

Instance Method Summary collapse

Instance Method Details

#camelizeObject



341
342
343
# File 'lib/strongspace/helpers.rb', line 341

def camelize
  self.split(/[^a-z0-9]/i).map{|w| w.capitalize}.join
end

#ends_with?(str) ⇒ Boolean

Returns:

  • (Boolean)


323
324
325
326
327
# File 'lib/strongspace/helpers.rb', line 323

def ends_with?(str)
  str = str.to_str
  tail = self[-str.length, str.length]
  tail == str
end

#from_cygpathObject



397
398
399
400
401
402
# File 'lib/strongspace/helpers.rb', line 397

def from_cygpath
  if self.starts_with? "/cygdrive" and Strongspace::Command::running_on_windows?
    return "#{self[10..10]}:\\#{self[12..-1].gsub("/","\\")}"
  end
  return self
end

#nice_slugObject



357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
# File 'lib/strongspace/helpers.rb', line 357

def nice_slug
  str = self.dup
  accents = {
  ['á','à','â','ä','ã'] => 'a',
  ['Ã','Ä','Â','À','Á'] => 'A',
  ['é','è','ê','ë'] => 'e',
  ['Ë','É','È','Ê'] => 'E',
  ['í','ì','î','ï'] => 'i',
  ['Í','Î','Ì','Ï'] => 'I',
  ['ó','ò','ô','ö','õ'] => 'o',
  ['Õ','Ö','Ô','Ò','Ó'] => 'O',
  ['ú','ù','û','ü'] => 'u',
  ['Ú','Û','Ù','Ü'] => 'U',
  ['ç'] => 'c', ['Ç'] => 'C',
  ['ñ'] => 'n', ['Ñ'] => 'N'
  }
  accents.each do |ac,rep|
    ac.each do |s|
      str = str.gsub(s, rep)
    end
  end
  str = str.gsub(/[^a-zA-Z0-9\. ]/,"")
  str = str.gsub(/[ ]+/," ")
  str = str.gsub(/[_]/,"-")
end

#normalize_pathslashObject



408
409
410
411
# File 'lib/strongspace/helpers.rb', line 408

def normalize_pathslash
  return self.gsub("/", "\\") if Strongspace::Command::running_on_windows?
  return self
end

#shellescapeObject



333
334
335
# File 'lib/strongspace/helpers.rb', line 333

def shellescape
  empty? ? "''" : gsub(/([^A-Za-z0-9_\-.,:\/@\n])/n, '\\\\\\1').gsub(/\n/, "'\n'")
end

#starts_with?(str) ⇒ Boolean

Returns:

  • (Boolean)


313
314
315
316
317
# File 'lib/strongspace/helpers.rb', line 313

def starts_with?(str)
  str = str.to_str
  head = self[0, str.length]
  head == str
end

#to_cygpathObject



387
388
389
390
391
# File 'lib/strongspace/helpers.rb', line 387

def to_cygpath
  return self unless Strongspace::Command::running_on_windows?
  r = "/cygdrive/#{self[0..0].downcase}/#{self[3..-1]}".gsub("\\", "/")
  return r
end

#underscoreObject



349
350
351
# File 'lib/strongspace/helpers.rb', line 349

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