Class: Build::Name

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

Overview

Represents a human-readable name with helpers for generating identifiers, target names, and macros.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Name

Initialize the name with the given text.



11
12
13
14
15
16
17
# File 'lib/build/name.rb', line 11

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

Instance Attribute Details

#text ⇒ Object (readonly)

Returns the value of attribute text.



26
27
28
# File 'lib/build/name.rb', line 26

def text
  @text
end

Class Method Details

.from_target(string) ⇒ Object

Construct a Build::Name from a hyphen-separated target name string.



22
23
24
# File 'lib/build/name.rb', line 22

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.



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

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

#identifier ⇒ String

Returns suitable for constant identifier.

Returns:

  • (String) —

    suitable for constant identifier.



29
30
31
# File 'lib/build/name.rb', line 29

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

#key(*postfix) ⇒ String

Returns suitable for variable name.

Returns:

  • (String) —

    suitable for variable name.



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

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.



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

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

#target ⇒ String

Returns suitable for target name.

Returns:

  • (String) —

    suitable for target name.



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

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