Sha256: 0f85b44c0cb5488b47c4f03934ae1d320ba513f2cca0cfbe419fbd4cfdcb1b16

Contents?: true

Size: 1000 Bytes

Versions: 5

Compression:

Stored size: 1000 Bytes

Contents

module Vnstat
  module Traffic
    ##
    # An abstract implementation for a traffic collection.
    #
    # @attr_reader [Interface] interface The tracked interface.
    class Base
      include Enumerable

      attr_reader :interface

      ##
      # Initializes the traffic collection.
      #
      # @param [Interface] interface The tracked interface.
      def initialize(interface)
        @interface = interface
      end

      ##
      # Iterates over all results in the collection.
      #
      # @overload each
      #   @return [Enumerator]
      #
      # @overload each(&block)
      #   @yield [result]
      #   @yieldparam [Result] result
      #   @return [Base]
      def each(&block)
        entries_hash.values.each(&block)
      end

      private

      def traffic_data
        interface.data.xpath('//traffic')
      end

      def entries_hash
        fail NotImplementedError,
             "Please override #{self.class.name}##{__method__}"
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
vnstat-ruby-1.0.4 lib/vnstat/traffic/base.rb
vnstat-ruby-1.0.3 lib/vnstat/traffic/base.rb
vnstat-ruby-1.0.2 lib/vnstat/traffic/base.rb
vnstat-ruby-1.0.1 lib/vnstat/traffic/base.rb
vnstat-ruby-1.0.0 lib/vnstat/traffic/base.rb