Class: Vnstat::Result
- Inherits:
-
Object
- Object
- Vnstat::Result
- Includes:
- Comparable
- Defined in:
- lib/vnstat/result.rb,
lib/vnstat/result/day.rb,
lib/vnstat/result/hour.rb,
lib/vnstat/result/month.rb,
lib/vnstat/result/minute.rb,
lib/vnstat/result/date_delegation.rb,
lib/vnstat/result/time_comparable.rb
Overview
A class representing a tracking result.
Defined Under Namespace
Modules: DateDelegation, TimeComparable Classes: Day, Hour, Minute, Month
Instance Attribute Summary collapse
-
#bytes_received ⇒ Integer
readonly
The received bytes.
-
#bytes_sent ⇒ Integer
readonly
The sent bytes.
Class Method Summary collapse
-
.extract_from_xml_element(element) ⇒ Result
Initializes a Result using the the data contained in the given XML element.
Instance Method Summary collapse
- #<=>(other) ⇒ Integer?
-
#bytes_transmitted ⇒ Integer
The transmitted bytes (both sent and received).
-
#initialize(bytes_received, bytes_sent) ⇒ Result
constructor
Initializes the Result.
Constructor Details
#initialize(bytes_received, bytes_sent) ⇒ Result
Initializes the Vnstat::Result.
28 29 30 31 |
# File 'lib/vnstat/result.rb', line 28 def initialize(bytes_received, bytes_sent) @bytes_received = bytes_received @bytes_sent = bytes_sent end |
Instance Attribute Details
#bytes_received ⇒ Integer (readonly)
Returns The received bytes.
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 |
# File 'lib/vnstat/result.rb', line 11 class Result autoload :DateDelegation, 'vnstat/result/date_delegation' autoload :Day, 'vnstat/result/day' autoload :Hour, 'vnstat/result/hour' autoload :Minute, 'vnstat/result/minute' autoload :Month, 'vnstat/result/month' autoload :TimeComparable, 'vnstat/result/time_comparable' include Comparable attr_reader :bytes_received, :bytes_sent ## # Initializes the {Result}. # # @param [Integer] bytes_received The received bytes. # @param [Integer] bytes_sent The sent bytes. def initialize(bytes_received, bytes_sent) @bytes_received = bytes_received @bytes_sent = bytes_sent end ## # Initializes a {Result} using the the data contained in the given XML # element. # # @param [Nokogiri::XML::Element] element The XML element. # @return [Result] def self.extract_from_xml_element(element) new(*Parser.extract_transmitted_bytes_from_xml_element(element)) end ## # The transmitted bytes (both sent and received). # # @return [Integer] def bytes_transmitted bytes_received + bytes_sent end ## # @return [Integer, nil] def <=>(other) return nil unless other.respond_to?(:bytes_transmitted) bytes_transmitted <=> other.bytes_transmitted end end |
#bytes_sent ⇒ Integer (readonly)
Returns The sent bytes.
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 |
# File 'lib/vnstat/result.rb', line 11 class Result autoload :DateDelegation, 'vnstat/result/date_delegation' autoload :Day, 'vnstat/result/day' autoload :Hour, 'vnstat/result/hour' autoload :Minute, 'vnstat/result/minute' autoload :Month, 'vnstat/result/month' autoload :TimeComparable, 'vnstat/result/time_comparable' include Comparable attr_reader :bytes_received, :bytes_sent ## # Initializes the {Result}. # # @param [Integer] bytes_received The received bytes. # @param [Integer] bytes_sent The sent bytes. def initialize(bytes_received, bytes_sent) @bytes_received = bytes_received @bytes_sent = bytes_sent end ## # Initializes a {Result} using the the data contained in the given XML # element. # # @param [Nokogiri::XML::Element] element The XML element. # @return [Result] def self.extract_from_xml_element(element) new(*Parser.extract_transmitted_bytes_from_xml_element(element)) end ## # The transmitted bytes (both sent and received). # # @return [Integer] def bytes_transmitted bytes_received + bytes_sent end ## # @return [Integer, nil] def <=>(other) return nil unless other.respond_to?(:bytes_transmitted) bytes_transmitted <=> other.bytes_transmitted end end |
Class Method Details
.extract_from_xml_element(element) ⇒ Result
Initializes a Vnstat::Result using the the data contained in the given XML element.
39 40 41 |
# File 'lib/vnstat/result.rb', line 39 def self.extract_from_xml_element(element) new(*Parser.extract_transmitted_bytes_from_xml_element(element)) end |
Instance Method Details
#<=>(other) ⇒ Integer?
53 54 55 56 57 |
# File 'lib/vnstat/result.rb', line 53 def <=>(other) return nil unless other.respond_to?(:bytes_transmitted) bytes_transmitted <=> other.bytes_transmitted end |
#bytes_transmitted ⇒ Integer
The transmitted bytes (both sent and received).
47 48 49 |
# File 'lib/vnstat/result.rb', line 47 def bytes_transmitted bytes_received + bytes_sent end |