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



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/modl/parser/instruction_processor.rb', line 6

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



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

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