Sha256: 5b69e64945eacfdeeae1ddf87312f89550387db9ae15977fe130acd71db009ef

Contents?: true

Size: 921 Bytes

Versions: 7

Compression:

Stored size: 921 Bytes

Contents

module Vnstat
  module Traffic
    ##
    # A class representing a collection of tracked tops.
    class Tops < Base
      ##
      # Iterates over all results in the collection.
      #
      # @overload each
      #   @return [Enumerator]
      #
      # @overload each(&block)
      #   @yield [result]
      #   @yieldparam [Result::Minute] result
      #   @return [Tops]
      def each(&block)
        to_a.each(&block)
      end

      ##
      # Fetches a single {Result::Minute} from the collection.
      #
      # @param [Integer] index The index of the entry in the collection.
      # @return [Result::Minute]
      def [](index)
        to_a[index]
      end

      ##
      # @return [Array<Result::Minute>]
      def to_a
        elements = traffic_data.xpath('tops/top')
        elements.map do |element|
          Result::Minute.extract_from_xml_element(element)
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
vnstat-ruby-1.1.0 lib/vnstat/traffic/tops.rb
vnstat-ruby-1.0.5 lib/vnstat/traffic/tops.rb
vnstat-ruby-1.0.4 lib/vnstat/traffic/tops.rb
vnstat-ruby-1.0.3 lib/vnstat/traffic/tops.rb
vnstat-ruby-1.0.2 lib/vnstat/traffic/tops.rb
vnstat-ruby-1.0.1 lib/vnstat/traffic/tops.rb
vnstat-ruby-1.0.0 lib/vnstat/traffic/tops.rb