Class: String

Inherits:
Object show all
Defined in:
lib/guerrilla_patch/string.rb

Instance Method Summary collapse

Instance Method Details

#indentObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/guerrilla_patch/string.rb', line 15

def indent
  tokens = self.split ("\n")
  result = ''
  if tokens.size > 0 
    prespace_index = tokens[0].index(/\S/)
    tokens.each do |token|
      result << token[prespace_index,(token.length - prespace_index)] << "\n"
    end
  end
  return result
end

#split_on_size(*args) ⇒ Object



2
3
4
5
6
7
# File 'lib/guerrilla_patch/string.rb', line 2

def split_on_size(*args)
  regex = args.to_a.inject('') { |regex, size| regex += "(\\w{#{size}})" }
  split(Regexp.compile("^#{regex}$")).reject do |item|
    item.blank? 
  end.join('-')
end

#upcase_romanObject



9
10
11
12
13
# File 'lib/guerrilla_patch/string.rb', line 9

def upcase_roman
  self =~ /(.*)(_[xX]?[vV]?[iI]{0,3}[vV]?[xX]?)$/
  return self if $1.nil? || $2.nil?
  return $1 + $2.upcase
end