Class: Vnstat::Result::Minute

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

Overview

A class representing a tracking result for a specific minute.

Instance Attribute Summary collapse

Attributes inherited from Vnstat::Result

#bytes_received, #bytes_sent

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TimeComparable

#<=>

Methods included from DateDelegation

#day, #month, #year

Methods inherited from Vnstat::Result

#<=>, #bytes_transmitted

Constructor Details

#initialize(time, bytes_received, bytes_sent) ⇒ Minute

Initializes the Vnstat::Result::Minute.

Parameters:

  • time (DateTime)

    The time the result was captured at.

  • bytes_received (Integer)

    The received bytes.

  • bytes_sent (Integer)

    The sent bytes.



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

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

Instance Attribute Details

#timeDateTime (readonly)

Returns The time the result was captured at.

Returns:

  • (DateTime)

    The time the result was captured at.



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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/vnstat/result/minute.rb', line 10

class Minute < Result
  include DateDelegation
  include TimeComparable

  attr_reader :time

  ##
  # Initializes the {Minute}.
  #
  # @param [DateTime] time The time the result was captured at.
  # @param [Integer] bytes_received The received bytes.
  # @param [Integer] bytes_sent The sent bytes.
  def initialize(time, bytes_received, bytes_sent)
    @time = time
    super(bytes_received, bytes_sent)
  end

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

  ##
  # The date the result was captured.
  #
  # @return [Date]
  def date
    time.to_date
  end

  ##
  # The hour the result was captured.
  #
  # @return [Integer]
  def hour
    time.hour
  end

  ##
  # The minute the result was captured.
  #
  # @return [Integer]
  def minute
    time.min
  end
end

Class Method Details

.extract_from_xml_element(element) ⇒ Minute

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

Parameters:

  • element (Nokogiri::XML::Element)

    The XML element.

Returns:



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

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

Instance Method Details

#dateDate

The date the result was captured.

Returns:

  • (Date)


44
45
46
# File 'lib/vnstat/result/minute.rb', line 44

def date
  time.to_date
end

#hourInteger

The hour the result was captured.

Returns:

  • (Integer)


52
53
54
# File 'lib/vnstat/result/minute.rb', line 52

def hour
  time.hour
end

#minuteInteger

The minute the result was captured.

Returns:

  • (Integer)


60
61
62
# File 'lib/vnstat/result/minute.rb', line 60

def minute
  time.min
end