Class: Mentawai::Core::ActionConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/mentawai/core/action_config.rb

Instance Method Summary collapse

Constructor Details

#initialize(className, name = nil, inner = nil) ⇒ ActionConfig

Returns a new instance of ActionConfig.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/mentawai/core/action_config.rb', line 6

def initialize(className, name = nil, inner = nil)
  @className = className
  if name == nil then
    @actionName = className
  else
    @actionName = name
  end
  @innerAction = inner
  @filters = Array.new
  @consequences = Hash.new
end

Instance Method Details

#actionNameObject



58
59
60
# File 'lib/mentawai/core/action_config.rb', line 58

def actionName
  @actionName
end

#classNameObject



54
55
56
# File 'lib/mentawai/core/action_config.rb', line 54

def className
  @className
end

#filter(filter) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/mentawai/core/action_config.rb', line 45

def filter(filter)
  if filter.is_a?(Array) then
    filter.each { |f| @filters.push(f) }
  else
    @filters.push(filter)
  end
  self
end

#filtersObject



66
67
68
69
70
# File 'lib/mentawai/core/action_config.rb', line 66

def filters
  @filters.each do |f|
    yield f
  end
end

#getConsequence(result) ⇒ Object



72
73
74
# File 'lib/mentawai/core/action_config.rb', line 72

def getConsequence(result)
  @consequences[result]
end

#innerActionObject



62
63
64
# File 'lib/mentawai/core/action_config.rb', line 62

def innerAction
  @innerAction
end

#on(result, conseq = nil) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/mentawai/core/action_config.rb', line 28

def on(result, conseq = nil)
  
  if conseq == nil then
    
    raise "Expecting a hash!" if !result.is_a?(Hash)
    
    result.each do |k,v|
      @consequences[k] = v
    end
    
  else
    @consequences[result] = conseq
  end
  
  self
end

#to_sObject



18
19
20
21
22
23
24
25
26
# File 'lib/mentawai/core/action_config.rb', line 18

def to_s
  s = "ActionConfig: " + @className
  s += " / " + @actionName
  if @innerAction != nil then
    s += " / " + @innerAction 
  else
    s += " / nil"
  end
end