Class: Vnstat::Result::Month

Inherits:
Vnstat::Result show all
Defined in:
lib/vnstat/result/month.rb

Overview

A class representing a tracking result for a specific month.

Instance Attribute Summary collapse

Attributes inherited from Vnstat::Result

#bytes_received, #bytes_sent

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Vnstat::Result

#bytes_transmitted

Constructor Details

#initialize(year, month, bytes_received, bytes_sent) ⇒ Month

Initializes the Vnstat::Result::Month.

Parameters:

  • year (Integer)

    The year the result was captured in.

  • month (Integer)

    The month the result was captured in.

  • bytes_received (Integer)

    The received bytes.

  • bytes_sent (Integer)

    The sent bytes.



22
23
24
25
26
# File 'lib/vnstat/result/month.rb', line 22

def initialize(year, month, bytes_received, bytes_sent)
  @year = year
  @month = month
  super(bytes_received, bytes_sent)
end

Instance Attribute Details

#monthInteger (readonly)

Returns The month the result was captured in.

Returns:

  • (Integer)

    The month the result was captured in.



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
48
49
50
# File 'lib/vnstat/result/month.rb', line 12

class Month < Result
  attr_reader :year, :month

  ##
  # Initializes the {Month}.
  #
  # @param [Integer] year The year the result was captured in.
  # @param [Integer] month The month the result was captured in.
  # @param [Integer] bytes_received The received bytes.
  # @param [Integer] bytes_sent The sent bytes.
  def initialize(year, month, bytes_received, bytes_sent)
    @year = year
    @month = month
    super(bytes_received, bytes_sent)
  end

  ##
  # Initializes a {Month} using the the data contained in the given XML
  # element.
  #
  # @param [Nokogiri::XML::Element] element The XML element.
  # @return [Month]
  def self.extract_from_xml_element(element)
    new(
      *Parser.extract_month_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 if !other.respond_to?(:year) || !other.respond_to?(:month)

    [year, month, bytes_transmitted] <=>
      [other.year, other.month, other.bytes_transmitted]
  end
end

#yearInteger (readonly)

Returns The year the result was captured in.

Returns:

  • (Integer)

    The year the result was captured in.



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
48
49
50
# File 'lib/vnstat/result/month.rb', line 12

class Month < Result
  attr_reader :year, :month

  ##
  # Initializes the {Month}.
  #
  # @param [Integer] year The year the result was captured in.
  # @param [Integer] month The month the result was captured in.
  # @param [Integer] bytes_received The received bytes.
  # @param [Integer] bytes_sent The sent bytes.
  def initialize(year, month, bytes_received, bytes_sent)
    @year = year
    @month = month
    super(bytes_received, bytes_sent)
  end

  ##
  # Initializes a {Month} using the the data contained in the given XML
  # element.
  #
  # @param [Nokogiri::XML::Element] element The XML element.
  # @return [Month]
  def self.extract_from_xml_element(element)
    new(
      *Parser.extract_month_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 if !other.respond_to?(:year) || !other.respond_to?(:month)

    [year, month, bytes_transmitted] <=>
      [other.year, other.month, other.bytes_transmitted]
  end
end

Class Method Details

.extract_from_xml_element(element) ⇒ Month

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

Parameters:

  • element (Nokogiri::XML::Element)

    The XML element.

Returns:



34
35
36
37
38
39
# File 'lib/vnstat/result/month.rb', line 34

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

Instance Method Details

#<=>(other) ⇒ Integer?

Returns:

  • (Integer, nil)


43
44
45
46
47
48
49
# File 'lib/vnstat/result/month.rb', line 43

def <=>(other)
  return nil unless other.respond_to?(:bytes_transmitted)
  return nil if !other.respond_to?(:year) || !other.respond_to?(:month)

  [year, month, bytes_transmitted] <=>
    [other.year, other.month, other.bytes_transmitted]
end