Class: Vnstat::Traffic::Tops

Inherits:
Base
  • Object
show all
Defined in:
lib/vnstat/traffic/tops.rb

Overview

A class representing a collection of tracked tops.

Instance Attribute Summary

Attributes inherited from Base

#interface

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Vnstat::Traffic::Base

Instance Method Details

#[](index) ⇒ Result::Minute

Fetches a single Result::Minute from the collection.

Parameters:

  • index (Integer)

    The index of the entry in the collection.

Returns:



27
28
29
# File 'lib/vnstat/traffic/tops.rb', line 27

def [](index)
  to_a[index]
end

#eachEnumerator #each {|result| ... } ⇒ Tops

Iterates over all results in the collection.

Overloads:

  • #eachEnumerator

    Returns:

    • (Enumerator)
  • #each {|result| ... } ⇒ Tops

    Yields:

    • (result)

    Yield Parameters:

    Returns:



18
19
20
# File 'lib/vnstat/traffic/tops.rb', line 18

def each(&block)
  to_a.each(&block)
end

#to_aArray<Result::Minute>

Returns:



33
34
35
36
37
38
# File 'lib/vnstat/traffic/tops.rb', line 33

def to_a
  elements = traffic_data.xpath('tops/top')
  elements.map do |element|
    Result::Minute.extract_from_xml_element(element)
  end
end