File: name_helper.rb

package info (click to toggle)
ruby-rgen 0.10.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,428 kB
  • sloc: ruby: 11,344; xml: 1,368; yacc: 72; makefile: 10
file content (42 lines) | stat: -rw-r--r-- 676 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# RGen Framework
# (c) Martin Thiede, 2006

module RGen

module Util

module NameHelper

	def normalize(name)
		name.gsub(/\W/,'_')
	end
	
	def className(object)
		object.class.name =~ /::(\w+)$/; $1
	end
	
	def firstToUpper(str)
		str[0..0].upcase + ( str[1..-1] || "" )
	end
	
	def firstToLower(str)
		str[0..0].downcase + ( str[1..-1] || "" )
	end
	
	def saneClassName(str)
		firstToUpper(normalize(str)).sub(/^Class$/, 'Clazz')
	end
	
	def saneMethodName(str)
		firstToLower(normalize(str)).sub(/^class$/, 'clazz')
	end	
	
  def camelize(str)
    str.split(/[\W_]/).collect{|s| firstToUpper(s.downcase)}.join
  end
end

end

end