Class: Vnstat::Result::Day

Inherits:
Vnstat::Result show all
Includes:
DateDelegation
Defined in:
lib/vnstat/result/day.rb

Overview

A class representing a tracking result for a specific day.

Instance Attribute Summary collapse

Attributes inherited from Vnstat::Result

#bytes_received, #bytes_sent

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DateDelegation

#day, #month, #year

Methods inherited from Vnstat::Result

#bytes_transmitted

Constructor Details

#initialize(date, bytes_received, bytes_sent) ⇒ Day

Initializes the Vnstat::Result::Day.

Parameters:

  • date (Date)

    The date the result was captured on.

  • bytes_received (Integer)

    The received bytes.

  • bytes_sent (Integer)

    The sent bytes.



21
22
23
24
# File 'lib/vnstat/result/day.rb', line 21

def initialize(date, bytes_received, bytes_sent)
  @date = date
  super(bytes_received, bytes_sent)
end

Instance Attribute Details

#dateDate (readonly)

Returns The date the result was captured on.

Returns:

  • (Date)

    The date the result was captured on.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/vnstat/result/day.rb', line 10

class Day < Result
  include DateDelegation

  attr_reader :date

  ##
  # Initializes the {Day}.
  #
  # @param [Date] date The date the result was captured on.
  # @param [Integer] bytes_received The received bytes.
  # @param [Integer] bytes_sent The sent bytes.
  def initialize(date, bytes_received, bytes_sent)
    @date = date
    super(bytes_received, bytes_sent)
  end

  ##
  # Initializes a {Day} using the the data contained in the given XML
  # element.
  #
  # @param [Nokogiri::XML::Element] element The XML element.
  # @return [Day]
  def self.extract_from_xml_element(element)
    new(
      Parser.extract_date_from_xml_element(element),
      *Parser.extract_transmitted_bytes_from_xml_element(element)
    )
  end

  ##
  # @return [Integer, nil]
  def <=>(other)
    return nil unless other.respond_to?(:bytes_transmitted)
    return nil unless other.respond_to?(:date)

    [date, bytes_transmitted] <=> [other.date, other.bytes_transmitted]
  end
end

Class Method Details

.extract_from_xml_element(element) ⇒ Day

Initializes a Vnstat::Result::Day using the the data contained in the given XML element.

Parameters:

  • element (Nokogiri::XML::Element)

    The XML element.

Returns:



32
33
34
35
36
37
# File 'lib/vnstat/result/day.rb', line 32

def self.extract_from_xml_element(element)
  new(
    Parser.extract_date_from_xml_element(element),
    *Parser.extract_transmitted_bytes_from_xml_element(element)
  )
end

Instance Method Details

#<=>(other) ⇒ Integer?

Returns:

  • (Integer, nil)


41
42
43
44
45
46
# File 'lib/vnstat/result/day.rb', line 41

def <=>(other)
  return nil unless other.respond_to?(:bytes_transmitted)
  return nil unless other.respond_to?(:date)

  [date, bytes_transmitted] <=> [other.date, other.bytes_transmitted]
end