Class: Riptables::RulePermutation
- Inherits:
-
Object
- Object
- Riptables::RulePermutation
- Defined in:
- lib/riptables/rule_permutation.rb
Instance Attribute Summary collapse
-
#conditions ⇒ Object
readonly
Returns the value of attribute conditions.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#rule ⇒ Object
readonly
Returns the value of attribute rule.
Instance Method Summary collapse
-
#initialize(rule, description, options = {}) ⇒ RulePermutation
constructor
A new instance of RulePermutation.
-
#to_rule ⇒ Object
Convert this permutation into a full rule in its own right.
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, = {}) @rule = rule @description = description = @conditions = Condition.conditions.dup - @rule.conditions end |
Instance Attribute Details
#conditions ⇒ Object (readonly)
Returns the value of attribute conditions.
17 18 19 |
# File 'lib/riptables/rule_permutation.rb', line 17 def conditions @conditions end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
15 16 17 |
# File 'lib/riptables/rule_permutation.rb', line 15 def description @description end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
16 17 18 |
# File 'lib/riptables/rule_permutation.rb', line 16 def end |
#rule ⇒ Object (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_rule ⇒ Object
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.[$1.to_sym] value else "{{#{$1}}}" end end new_rule.action = rule.action new_rule.conditions = rule.conditions | self.conditions if v = (self.[:v] || self.[:version]) new_rule.versions = [v.to_i] end new_rule end |