class Vnstat::Result::Hour
A class representing a tracking result for a specific hour.
@!attribute [r] date
@return [Date] The date the result was captured on.
@!attribute [r] hour
@return [Integer] The hour the result was captured at.
Attributes
date[R]
hour[R]
Public Class Methods
extract_from_xml_element(element)
click to toggle source
Initializes a {Hour} using the the data contained in the given XML element.
@param [Nokogiri::XML::Element] element The XML element. @return [Hour]
# File lib/vnstat/result/hour.rb, line 37 def self.extract_from_xml_element(element) date = Parser.extract_date_from_xml_element(element) hour = Integer(element.attr('id').to_s) new( date, hour, *Parser.extract_transmitted_bytes_from_xml_element(element) ) end
new(date, hour, bytes_received, bytes_sent)
click to toggle source
Initializes the {Hour}.
@param [Date] date The date the result was captured on. @param [Integer] hour The hour the result was captured at. @param [Integer] bytes_received The received bytes. @param [Integer] bytes_sent The sent bytes.
Calls superclass method
Vnstat::Result::new
# File lib/vnstat/result/hour.rb, line 25 def initialize(date, hour, bytes_received, bytes_sent) @date = date @hour = hour super(bytes_received, bytes_sent) end
Public Instance Methods
<=>(other)
click to toggle source
@return [Integer, nil]
# File lib/vnstat/result/hour.rb, line 49 def <=>(other) return nil unless other.respond_to?(:bytes_transmitted) return nil unless other.respond_to?(:time) [time, bytes_transmitted] <=> [other.time, other.bytes_transmitted] end
time()
click to toggle source
The time the result was captured.
@return [DateTime]
# File lib/vnstat/result/hour.rb, line 60 def time DateTime.new(year, month, day, hour, 0, 0, DateTime.now.offset) end