Class: MODL::Parser::RefProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/modl/parser/ref_processor.rb

Overview

Convert MODL reference to the replacement value

Constant Summary collapse

NESTED_SEPARATOR =
'.'
MATCHER =
Regexp.new('((`?\%[0-9][0-9.][a-zA-Z0-9.(),]*`?)|(`?\%[0-9][0-9]*`?)|(`?\%[_a-zA-Z][_a-zA-Z0-9.%(),]*`?)|(`.*`\.[_a-zA-Z0-9.(),%]+)|(`.*`))')

Class Method Summary collapse

Class Method Details

.deref(str, global) ⇒ Object

Check str for references and process them. Return the processed string and a new_value if there is one.



22
23
24
25
26
# File 'lib/modl/parser/ref_processor.rb', line 22

def self.deref(str, global)
  obj = str
  obj, new_value = split_by_ref_tokens str, global if trivial_reject(str)
  [obj, new_value]
end

.split_by_ref_tokens(str, global) ⇒ Object

Process the next %ref token



29
30
31
32
33
34
35
36
37
38
# File 'lib/modl/parser/ref_processor.rb', line 29

def self.split_by_ref_tokens(str, global)
  new_value = nil

  text = str
  original = str

  new_value, str = process_tokens(global, original, str, text) if new_value.nil?

  [str, new_value]
end

.trivial_reject(str) ⇒ Object



15
16
17
18
# File 'lib/modl/parser/ref_processor.rb', line 15

def self.trivial_reject(str)
  # do a fast check to see if we need to deref - save processing the regex if we don't have to.
  str.is_a?(String) && (str.nil? || str.include?('%') || str.include?('`'))
end