Class: MODL::Parser::InstructionProcessor

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

Overview

This class handles the conversion of objects that refer to classes into instances of those classes. It works recursively since class usage can be nested.

Class Method Summary collapse

Class Method Details

.process(global, obj) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/modl/parser/instruction_processor.rb', line 30

def self.process(global, obj)
  if obj.is_a? Hash
    nvals = {}
    obj.keys.each do |k|
      o = obj[k]
      if o.is_a? String
        nv = process_instruction(global, o)
        nvals[k] = nv unless nv.nil?
      else
        process(global, o)
      end
    end
    obj.merge!(nvals)
  elsif obj.is_a? Array
    i = 0
    while i < obj.length
      o = obj[i]
      if o.is_a? String
        nv = process_instruction(global, o)
        obj[i] = nv unless nv.nil?
      else
        process(global, o)
      end
      i += 1
    end
  end
end

.process_instruction(global, str) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/modl/parser/instruction_processor.rb', line 58

def self.process_instruction(global, str)
  case str
  when '%*class'
    return global.class_list
  when '%*method'
    return global.method_list
  when '%*load'
    return global.file_list
  when '%*id'
    return global.id_list
  when '%*name'
    return global.name_list
  when '%*superclass'
    return global.superclass_list
  when '%*assign'
    return global.assign_list
  when '%*transform'
    return global.transform_list
  when '%*allow'
    return global.allow_list
  when '%*expect'
    return global.allow_list
  end
end