Parent

Files

String

Public Class Methods

letters(type = :lower) click to toggle source
# File lib/sugar-high/string.rb, line 8
def self.letters type = :lower
  letters = ('a'..'z').to_a
  type == :upper ? letters.map!(&:upcase) : letters
end
random_letters(count, type = :lower) click to toggle source
# File lib/sugar-high/string.rb, line 4
def self.random_letters count, type = :lower
 letters(type).pick(count)
end

Public Instance Methods

alpha_numeric() click to toggle source

remove prefixed '-' signs, then allow any letter, number, underscore '_' or dash '-'

# File lib/sugar-high/string.rb, line 26
def alpha_numeric
  self.gsub(/^\-+/, '').gsub(/[^0-9a-zA-Z_\-]+/, '')
end
args() click to toggle source
# File lib/sugar-high/arguments.rb, line 33
def args
  (self =~ /\w+\s+\w+/) ? self.split : self
end
as_filename() click to toggle source
# File lib/sugar-high/file.rb, line 40
def as_filename
  self.underscore
end
blank?() click to toggle source
# File lib/sugar-high/blank.rb, line 29
def blank?
  self !~ /\S/
end
concats(*args) click to toggle source
# File lib/sugar-high/string.rb, line 18
def concats *args
  args.inject(self) do |res, arg|
    res << arg.to_s
    res
  end
end
dir() click to toggle source
# File lib/sugar-high/file.rb, line 53
def dir
  return ::Dir.new(self) if ::File.directory?(self)
  raise "No file found at #{self}"
end
file() click to toggle source
# File lib/sugar-high/file.rb, line 48
def file
  return ::File.new(self) if ::File.file?(self)
  raise "No file found at #{self}"
end
insert_before_last(str, marker = 'end') click to toggle source
# File lib/sugar-high/string.rb, line 30
def insert_before_last str, marker = 'end'
  res = []
  found = false
  marker = case marker
  when Symbol, String
    marker.to_s
  when Hash
    marker[:marker].to_s
  else
    raise ArgumentException, "last argument is the marker and must be a String, Symbol or even Hash with a :marker option pointing to the marker (String or Symbol)"
  end

  marker = Regexp.escape(marker.to_s.reverse)
  nl = Regexp.escape("\n")
  self.reverse.each_line do |x|
    x.gsub! /#{nl}/, ''
    if !found && x =~ /#{marker}/
      replace = "#{str}\n" << x.reverse
      res << replace
      found = true
    else
      res << x.reverse
    end
  end
  res = res.reverse.join("\n")
end
new_file() click to toggle source
# File lib/sugar-high/file.rb, line 58
def new_file
  begin
    file
  rescue
    File.open(self, 'w')
  end
end
path() click to toggle source
# File lib/sugar-high/path.rb, line 2
def path
  self.extend PathString
end
to_regexp() click to toggle source
# File lib/sugar-high/regexp.rb, line 2
def to_regexp
  /#{Regexp.escape(self)}/
end
trim() click to toggle source
# File lib/sugar-high/string.rb, line 13
def trim
  self.strip
end
valid_file_command?() click to toggle source
# File lib/sugar-high/file.rb, line 44
def valid_file_command?
  self.to_sym.valid_file_command?
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.