Class: Havox::Rule
- Inherits:
-
Object
- Object
- Havox::Rule
- Defined in:
- lib/havox/classes/rule.rb
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
-
#dp_id ⇒ Object
readonly
Returns the value of attribute dp_id.
-
#matches ⇒ Object
readonly
Returns the value of attribute matches.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
Instance Method Summary collapse
-
#initialize(raw, opts = {}) ⇒ Rule
constructor
A new instance of Rule.
- #inspect ⇒ Object
- #to_h ⇒ Object
-
#to_s ⇒ Object
Stringifies the rule.
Constructor Details
#initialize(raw, opts = {}) ⇒ Rule
Returns a new instance of Rule.
5 6 7 8 9 10 11 12 13 |
# File 'lib/havox/classes/rule.rb', line 5 def initialize(raw, opts = {}) @opts = opts @syntax = @opts[:syntax] || :trema @matches = parsed_matches(raw) @actions = parsed_actions(raw) @dp_id = @matches[:dp_id].to_i @matches.delete(:dp_id) @raw = raw.strip end |
Instance Attribute Details
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
3 4 5 |
# File 'lib/havox/classes/rule.rb', line 3 def actions @actions end |
#dp_id ⇒ Object (readonly)
Returns the value of attribute dp_id.
3 4 5 |
# File 'lib/havox/classes/rule.rb', line 3 def dp_id @dp_id end |
#matches ⇒ Object (readonly)
Returns the value of attribute matches.
3 4 5 |
# File 'lib/havox/classes/rule.rb', line 3 def matches @matches end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
3 4 5 |
# File 'lib/havox/classes/rule.rb', line 3 def raw @raw end |
Instance Method Details
#inspect ⇒ Object
24 25 26 |
# File 'lib/havox/classes/rule.rb', line 24 def inspect "Rule #{object_id.to_s(16)}, dp_id = #{@dp_id}: #{to_s}" # Prints the rule when debugging or array listing. end |
#to_h ⇒ Object
28 29 30 |
# File 'lib/havox/classes/rule.rb', line 28 def to_h { dp_id: @dp_id, matches: @matches, actions: @actions } end |
#to_s ⇒ Object
Stringifies the rule.
15 16 17 18 19 20 21 22 |
# File 'lib/havox/classes/rule.rb', line 15 def to_s # Stringifies the rule. sep = ' AND ' matches_str = @matches.map { |k, v| "#{k.to_s} = #{v.to_s}" }.join(sep) actions_str = @actions.map do |o| %Q(#{o[:action]}(#{o[:arg_a]}#{", #{o[:arg_b]}" unless o[:arg_b].nil?})) end "#{matches_str} --> #{actions_str.join(sep)}" end |