class Name
Represents a human-readable name with helpers for generating identifiers, target names, and macros.
Definitions
def initialize(text)
Initialize the name with the given text.
Signature
-
parameter
textString The human-readable name text.
Implementation
def initialize(text)
@text = text
@identifier = nil
@target = nil
@key = nil
end
def self.from_target(string)
Construct a class Build::Name from a hyphen-separated target name string.
Signature
-
parameter
stringString A target name such as
"foo-bar".-
returns
Build::Name The corresponding name instance.
Implementation
def self.from_target(string)
self.new(string.gsub(/(^|[ \-_])(.)/){" " + $2.upcase}.strip)
end
def identifier
Implementation
def identifier
@identifier ||= @text.gsub(/\s+/, "")
end
def target
Implementation
def target
@target ||= @text.gsub(/\s+/, "-").downcase
end
def key(*postfix)
Implementation
def key(*postfix)
@key ||= ([@text] + postfix).collect{|part| part.downcase.gsub(/\s+/, "_")}.join("_")
end
def macro(prefix = [])
Implementation
def macro(prefix = [])
(Array(prefix) + [@text]).collect{|name| name.upcase.gsub(/\s+/, "_")}.join("_")
end
def header_guard(path)
Implementation
def header_guard(path)
macro(path) + "_H"
end