Sha256: e15bff0b0e71a81c6dc731a89784d3ff4a7f477916f631236ed74d80313ff7a2

Contents?: true

Size: 706 Bytes

Versions: 7

Compression:

Stored size: 706 Bytes

Contents

# frozen_string_literal: true

module Vnstat
  module Traffic
    ##
    # A class encapsulating monthly tracking information.
    class Monthly < Base
      ##
      # Fetches a single {Result::Month} from the collection.
      #
      # @param [Integer] year
      # @param [Integer] month
      # @return [Result::Month]
      def [](year, month)
        entries_hash[[year, month]]
      end

      private

      def entries_hash
        elements = traffic_data.xpath('months/month')
        elements.each_with_object({}) do |element, hash|
          result = Result::Month.extract_from_xml_element(element)
          hash[[result.year, result.month]] = result
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
vnstat-ruby-3.0.7 lib/vnstat/traffic/monthly.rb
vnstat-ruby-3.0.6 lib/vnstat/traffic/monthly.rb
vnstat-ruby-3.0.5 lib/vnstat/traffic/monthly.rb
vnstat-ruby-3.0.4 lib/vnstat/traffic/monthly.rb
vnstat-ruby-3.0.2 lib/vnstat/traffic/monthly.rb
vnstat-ruby-3.0.0 lib/vnstat/traffic/monthly.rb
vnstat-ruby-2.0.0 lib/vnstat/traffic/monthly.rb