Sha256: 94a3831a95f774ab4b19cc6e49b58e3339ef065c428c7e1f3fc208cb9c4f6550

Contents?: true

Size: 1.04 KB

Versions: 6

Compression:

Stored size: 1.04 KB

Contents

module Vnstat
  module Traffic
    ##
    # A class encapsulating daily tracking information.
    class Daily < Base
      ##
      # Fetches a single {Result::Day} from the collection.
      #
      # @return [Result::Day]
      #
      # @overload [](date)
      #   @param [Date] date
      #
      # @overload [](year, month, day)
      #   @param [Integer] year
      #   @param [Integer] month
      #   @param [Integer] day
      def [](*args)
        date = case args.count
               when 1 then args.first
               when 3 then Date.new(*args)
               else
                 fail ArgumentError, 'wrong number of arguments ' \
                                     "(#{args.count} for 1 or 3)"
               end
        entries_hash[date]
      end

      private

      def entries_hash
        elements = traffic_data.xpath('days/day')
        elements.each_with_object({}) do |element, hash|
          result = Result::Day.extract_from_xml_element(element)
          hash[result.date] = result
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

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