Class: Vnstat::Result::Day
- Inherits:
-
Vnstat::Result
- Object
- Vnstat::Result
- Vnstat::Result::Day
- Includes:
- DateDelegation
- Defined in:
- lib/vnstat/result/day.rb
Overview
A class representing a tracking result for a specific day.
Instance Attribute Summary collapse
-
#date ⇒ Date
readonly
The date the result was captured on.
Attributes inherited from Vnstat::Result
Class Method Summary collapse
-
.extract_from_xml_element(element) ⇒ Day
Initializes a Day using the the data contained in the given XML element.
Instance Method Summary collapse
- #<=>(other) ⇒ Integer?
-
#initialize(date, bytes_received, bytes_sent) ⇒ Day
constructor
Initializes the Day.
Methods included from DateDelegation
Methods inherited from Vnstat::Result
Constructor Details
#initialize(date, bytes_received, bytes_sent) ⇒ Day
Initializes the Vnstat::Result::Day.
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
#date ⇒ Date (readonly)
Returns 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.
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?
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 |