Class: Build::Name
- Inherits:
-
Object
- Object
- Build::Name
- Defined in:
- lib/build/name.rb
Instance Attribute Summary collapse
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Class Method Summary collapse
Instance Method Summary collapse
-
#header_guard(path) ⇒ String
Suitable for C header guard macro.
-
#identifier ⇒ String
Suitable for constant identifier.
-
#initialize(text) ⇒ Name
constructor
A new instance of Name.
-
#key(*postfix) ⇒ String
Suitable for variable name.
-
#macro(prefix = []) ⇒ String
Suitable for C macro name.
-
#target ⇒ String
Suitable for target name.
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
#text ⇒ Object (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.
58 59 60 |
# File 'lib/build/name.rb', line 58 def header_guard(path) macro(path) + '_H' end |
#identifier ⇒ String
Returns 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.
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.
53 54 55 |
# File 'lib/build/name.rb', line 53 def macro(prefix = []) (Array(prefix) + [@text]).collect{|name| name.upcase.gsub(/\s+/, '_')}.join('_') end |
#target ⇒ String
Returns suitable for target name.
43 44 45 |
# File 'lib/build/name.rb', line 43 def target @target ||= @text.gsub(/\s+/, '-').downcase end |