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