Class: Riptables::RulePermutation

Inherits:
Object
  • Object
show all
Defined in:
lib/riptables/rule_permutation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rule, description, options = {}) ⇒ RulePermutation

Returns a new instance of RulePermutation.



7
8
9
10
11
12
# File 'lib/riptables/rule_permutation.rb', line 7

def initialize(rule, description, options = {})
  @rule = rule
  @description = description
  @options = options
  @conditions = Condition.conditions.dup - @rule.conditions
end

Instance Attribute Details

#conditionsObject (readonly)

Returns the value of attribute conditions.



17
18
19
# File 'lib/riptables/rule_permutation.rb', line 17

def conditions
  @conditions
end

#descriptionObject (readonly)

Returns the value of attribute description.



15
16
17
# File 'lib/riptables/rule_permutation.rb', line 15

def description
  @description
end

#optionsObject (readonly)

Returns the value of attribute options.



16
17
18
# File 'lib/riptables/rule_permutation.rb', line 16

def options
  @options
end

#ruleObject (readonly)

Returns the value of attribute rule.



14
15
16
# File 'lib/riptables/rule_permutation.rb', line 14

def rule
  @rule
end

Instance Method Details

#to_ruleObject

Convert this permutation into a full rule in its own right



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/riptables/rule_permutation.rb', line 22

def to_rule
  new_rule = Rule.new(rule.chain)
  new_rule.description = "#{rule.description} (#{self.description})"
  new_rule.rule = rule.rule.gsub(/\{\{(\w+)\}\}/) do
    if value = self.options[$1.to_sym]
      value
    else
      "{{#{$1}}}"
    end
  end
  new_rule.action = rule.action
  new_rule.conditions = rule.conditions | self.conditions
  if v = (self.options[:v] || self.options[:version])
    new_rule.versions = [v.to_i]
  end
  new_rule
end