Class: Mu::Xtractr::Views::Sum
- Inherits:
-
Object
- Object
- Mu::Xtractr::Views::Sum
- Defined in:
- lib/mu/xtractr/views.rb,
lib/mu/xtractr/test/tc_views.rb
Overview
Count
Defined Under Namespace
Classes: Test
Instance Attribute Summary collapse
-
#field ⇒ Object
readonly
Returns the field used for summing.
-
#sum ⇒ Object
readonly
Returns the aggregate computed sum.
-
#value ⇒ Object
readonly
Returns the unique value used as the map/reduce key.
-
#xtractr ⇒ Object
readonly
:nodoc:.
Instance Method Summary collapse
-
#count(_field) ⇒ Object
Count the unique values of the specified field amongst all the packets that matched the query.
-
#each_packet(q = nil, &blk) ⇒ Object
Iterate over each packet that contains this field value.
-
#initialize(xtractr, field, value, sum) ⇒ Sum
constructor
:nodoc:.
-
#inspect ⇒ Object
:nodoc:.
-
#object ⇒ Object
Returns a Field::Value object that can be used for further method chaining.
-
#packets(q = nil) ⇒ Object
Fetch the list of packets that contain this field value.
Constructor Details
#initialize(xtractr, field, value, sum) ⇒ Sum
:nodoc:
99 100 101 102 103 104 |
# File 'lib/mu/xtractr/views.rb', line 99 def initialize xtractr, field, value, sum # :nodoc: @xtractr = xtractr @field = field @value = value @sum = sum end |
Instance Attribute Details
#field ⇒ Object (readonly)
Returns the field used for summing.
91 92 93 |
# File 'lib/mu/xtractr/views.rb', line 91 def field @field end |
#sum ⇒ Object (readonly)
Returns the aggregate computed sum.
97 98 99 |
# File 'lib/mu/xtractr/views.rb', line 97 def sum @sum end |
#value ⇒ Object (readonly)
Returns the unique value used as the map/reduce key.
94 95 96 |
# File 'lib/mu/xtractr/views.rb', line 94 def value @value end |
#xtractr ⇒ Object (readonly)
:nodoc:
88 89 90 |
# File 'lib/mu/xtractr/views.rb', line 88 def xtractr @xtractr end |
Instance Method Details
#count(_field) ⇒ Object
Count the unique values of the specified field amongst all the packets that matched the query.
xtractr.flows.sum('flow.src', 'flow.bytes').first.count('flow.service')
131 132 133 |
# File 'lib/mu/xtractr/views.rb', line 131 def count _field object.count _field end |
#each_packet(q = nil, &blk) ⇒ Object
Iterate over each packet that contains this field value.
xtractr.flows.sum('flow.src', 'flow.bytes').first.each_packet { |pkt ... }
123 124 125 126 |
# File 'lib/mu/xtractr/views.rb', line 123 def each_packet q=nil, &blk packets(q).each(&blk) return self end |
#inspect ⇒ Object
:nodoc:
135 136 137 |
# File 'lib/mu/xtractr/views.rb', line 135 def inspect # :nodoc: "#<sum #{value} #{sum}>" end |
#object ⇒ Object
Returns a Field::Value object that can be used for further method chaining. In the following example, we first compute the top talkers (based on the bytes sent) and then use the topmost talker to count the list of unique services.
xtractr.flows.sum('flow.src', 'flow.bytes').first.object.count('flow.service')
111 112 113 |
# File 'lib/mu/xtractr/views.rb', line 111 def object Field::Value.new xtractr, "key" => field.name, "value" => value end |
#packets(q = nil) ⇒ Object
Fetch the list of packets that contain this field value.
xtractr.flows.sum('flow.src', 'flow.bytes').first.packets.each { |pkt ... }
117 118 119 |
# File 'lib/mu/xtractr/views.rb', line 117 def packets q=nil object.packets q end |