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

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 22
def initialize(str)
  @macro_string = 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 32
def <=>(obj)
  demacro <=> obj
end
demacro() click to toggle source

returns string without MACRO_SYMBOL and DELIMITERS

# File lib/ruby_ext/macro.rb, line 42
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 37
  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

  # returns nil if not, and match data for any parameter names found
  def parameterized?
    macro_string.match Regexp.identifier
  end
end
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 27
def is_macro?(str)
  str[0,2] == MACRO_SYMBOL+DELIMITERS.first && str[-1] == DELIMITERS.last && str.balanced_parens?
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 47
def parameterized?
  macro_string.match Regexp.identifier
end