Class: Vnstat::Result::Hour
- Inherits:
-
Vnstat::Result
- Object
- Vnstat::Result
- Vnstat::Result::Hour
- Includes:
- DateDelegation, TimeComparable
- Defined in:
- lib/vnstat/result/hour.rb
Overview
A class representing a tracking result for a specific hour.
Instance Attribute Summary collapse
-
#date ⇒ Date
readonly
The date the result was captured on.
-
#hour ⇒ Integer
readonly
The hour the result was captured at.
Attributes inherited from Vnstat::Result
Class Method Summary collapse
-
.extract_from_xml_element(element) ⇒ Hour
Initializes a Hour using the the data contained in the given XML element.
Instance Method Summary collapse
- #<=>(other) ⇒ Integer?
-
#initialize(date, hour, bytes_received, bytes_sent) ⇒ Hour
constructor
Initializes the Hour.
-
#time ⇒ DateTime
The time the result was captured.
Methods included from DateDelegation
Methods inherited from Vnstat::Result
Constructor Details
#initialize(date, hour, bytes_received, bytes_sent) ⇒ Hour
Initializes the Vnstat::Result::Hour.
25 26 27 28 29 |
# 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 |
Instance Attribute Details
#date ⇒ Date (readonly)
Returns The date the result was captured on.
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/hour.rb', line 12 class Hour < Result include DateDelegation include TimeComparable attr_reader :date, :hour ## # 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. def initialize(date, hour, bytes_received, bytes_sent) @date = date @hour = hour super(bytes_received, bytes_sent) end ## # Initializes a {Hour} using the the data contained in the given XML # element. # # @param [Nokogiri::XML::Element] element The XML element. # @return [Hour] 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 ## # @return [Integer, nil] 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 ## # The time the result was captured. # # @return [DateTime] def time DateTime.new(year, month, day, hour, 0, 0, DateTime.now.offset) end end |
#hour ⇒ Integer (readonly)
Returns The hour the result was captured at.
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/hour.rb', line 12 class Hour < Result include DateDelegation include TimeComparable attr_reader :date, :hour ## # 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. def initialize(date, hour, bytes_received, bytes_sent) @date = date @hour = hour super(bytes_received, bytes_sent) end ## # Initializes a {Hour} using the the data contained in the given XML # element. # # @param [Nokogiri::XML::Element] element The XML element. # @return [Hour] 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 ## # @return [Integer, nil] 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 ## # The time the result was captured. # # @return [DateTime] def time DateTime.new(year, month, day, hour, 0, 0, DateTime.now.offset) end end |
Class Method Details
.extract_from_xml_element(element) ⇒ Hour
Initializes a Vnstat::Result::Hour using the the data contained in the given XML element.
37 38 39 40 41 42 43 44 45 |
# 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 |
Instance Method Details
#<=>(other) ⇒ Integer?
49 50 51 52 53 54 |
# 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 ⇒ DateTime
The time the result was captured.
60 61 62 |
# File 'lib/vnstat/result/hour.rb', line 60 def time DateTime.new(year, month, day, hour, 0, 0, DateTime.now.offset) end |