Class: Rmk::Rule

Inherits:
Object
  • Object
show all
Defined in:
lib/rmk/rule.rb

Defined Under Namespace

Classes: Var

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command) ⇒ Rule

create Rule

Parameters:

  • command (String)

    exec command template



8
9
10
11
12
# File 'lib/rmk/rule.rb', line 8

def initialize(command)
	@command = command
	@vars = {}
	@rmk_vars = {'out'=>nil, 'collection'=>nil}
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



13
14
15
# File 'lib/rmk/rule.rb', line 13

def command
  @command
end

Instance Method Details

#[](name) ⇒ Object



17
# File 'lib/rmk/rule.rb', line 17

def [](name) @rmk_vars[name] end

#[]=(name, append = false, value) ⇒ Object

add var define template



21
22
23
24
25
# File 'lib/rmk/rule.rb', line 21

def []=(name, append = false, value)
	return @vars[name] = Var.new(append, value) unless @rmk_vars.include? name
	raise "special var '#{name}' can't be append" if append
	@rmk_vars[name] = value
end

#apply_to(tgt) ⇒ Object



27
28
29
# File 'lib/rmk/rule.rb', line 27

def apply_to(tgt)
	@vars.each{|name, var| var.append? ? tgt[name] += var.value : tgt[name] = var.value }
end

#varsObject



15
# File 'lib/rmk/rule.rb', line 15

def vars; self end