class Macro
string wrapped in parameter expression macro symbol and delimiters, indicating content is to be parsed and resolved when building and validating XML design
Constants
- DELIMITERS
are parentheses by default e.g. '()'
- MACRO_SYMBOL
is '@' by default
Attributes
macro_string[RW]
string including MACRO_SYMBOL
and DELIMITERS
Public Class Methods
is_macro?(str)
click to toggle source
checks a string to see if it's a valid macro expression without leading or trailing non-expression or delimiter text
# File lib/ruby_ext/macro.rb, line 21 def self.is_macro?(str) str[0,2] == MACRO_SYMBOL+DELIMITERS.first && str[-1] == DELIMITERS.last && str.balanced_parens? end
new(str)
click to toggle source
takes given string and wraps in MACRO_SYMBOL
and DELIMITERS
if not already wrapped e.g. str => 'asdf'
Macro.new str => '@(asdf)'
# File lib/ruby_ext/macro.rb, line 28 def initialize(str) @macro_string = Macro.is_macro?(str) ? str : "#{MACRO_SYMBOL}#{DELIMITERS.first}#{str}#{DELIMITERS.last}" end
Public Instance Methods
<=>(obj)
click to toggle source
compares demacro
'd @macro_string to obj
# File lib/ruby_ext/macro.rb, line 33 def <=>(obj) demacro <=> obj end
demacro()
click to toggle source
returns string without MACRO_SYMBOL
and DELIMITERS
# File lib/ruby_ext/macro.rb, line 43 def demacro macro_string[2..-2] end
each() { |char end| ... }
click to toggle source
just yields each character of demacro
'd @macro_string
# File lib/ruby_ext/macro.rb, line 38 def each(&block) demacro.split(//).each do |char| yield char end end # returns string without MACRO_SYMBOL and DELIMITERS def demacro macro_string[2..-2] end def to_s macro_string end # returns nil if not, and match data for any parameter names found def parameterized? return false if macro_string[2] == '"' && macro_string[-2] == '"' macro_string.match Regexp.identifier end end
parameterized?()
click to toggle source
returns nil if not, and match data for any parameter names found
# File lib/ruby_ext/macro.rb, line 52 def parameterized? return false if macro_string[2] == '"' && macro_string[-2] == '"' macro_string.match Regexp.identifier end
to_s()
click to toggle source
# File lib/ruby_ext/macro.rb, line 47 def to_s macro_string end