Class: Build::Name

Inherits:
Object
  • Object
show all
Defined in:
lib/build/name.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Name

Returns a new instance of Name.



23
24
25
26
27
28
29
# File 'lib/build/name.rb', line 23

def initialize(text)
	@text = text
	
	@identifier = nil
	@target = nil
	@key = nil
end

Instance Attribute Details

#textObject (readonly)

Returns the value of attribute text.



35
36
37
# File 'lib/build/name.rb', line 35

def text
  @text
end

Class Method Details

.from_target(string) ⇒ Object



31
32
33
# File 'lib/build/name.rb', line 31

def self.from_target(string)
	self.new(string.gsub(/(^|[ \-_])(.)/){" " + $2.upcase}.strip)
end

Instance Method Details

#header_guard(path) ⇒ String

Returns suitable for C header guard macro.

Returns:

  • (String)

    suitable for C header guard macro.



58
59
60
# File 'lib/build/name.rb', line 58

def header_guard(path)
	macro(path) + '_H'
end

#identifierString

Returns suitable for constant identifier.

Returns:

  • (String)

    suitable for constant identifier.



38
39
40
# File 'lib/build/name.rb', line 38

def identifier
	@identifier ||= @text.gsub(/\s+/, '')
end

#key(*postfix) ⇒ String

Returns suitable for variable name.

Returns:

  • (String)

    suitable for variable name.



48
49
50
# File 'lib/build/name.rb', line 48

def key(*postfix)
	@key ||= ([@text] + postfix).collect{|part| part.downcase.gsub(/\s+/, '_')}.join('_')
end

#macro(prefix = []) ⇒ String

Returns suitable for C macro name.

Returns:

  • (String)

    suitable for C macro name.



53
54
55
# File 'lib/build/name.rb', line 53

def macro(prefix = [])
	(Array(prefix) + [@text]).collect{|name| name.upcase.gsub(/\s+/, '_')}.join('_')
end

#targetString

Returns suitable for target name.

Returns:

  • (String)

    suitable for target name.



43
44
45
# File 'lib/build/name.rb', line 43

def target
	@target ||= @text.gsub(/\s+/, '-').downcase
end