Class: Vnstat::InterfaceCollection
- Includes:
- Enumerable
- Defined in:
- lib/vnstat/interface_collection.rb
Overview
A class encapsulating traffic information for all known network interfaces.
Instance Attribute Summary
Attributes inherited from Document
Class Method Summary collapse
-
.load_data ⇒ String
Retrieves the raw XML data for all interfaces.
Instance Method Summary collapse
-
#[](id) ⇒ Interface
Returns traffic information for a certain interface.
-
#create(id) ⇒ Interface?
Creates the traffic database for the given interface.
-
#data=(data) ⇒ Object
Sets the raw XML data for the InterfaceCollection.
-
#each {|interface| ... } ⇒ Object
Iterates over each interface.
-
#ids ⇒ Array<String>
Returns the names of known interfaces.
-
#inspect ⇒ String
A human readable representation of the InterfaceCollection.
-
#rebuild ⇒ InterfaceCollection
Reset the total traffic counters and recount those using recorded months.
-
#reload ⇒ InterfaceCollection
Refreshes data cached in the current instance.
Methods inherited from Document
#initialize, open, #version, #xml_version
Constructor Details
This class inherits a constructor from Vnstat::Document
Class Method Details
.load_data ⇒ String
Retrieves the raw XML data for all interfaces.
13 14 15 |
# File 'lib/vnstat/interface_collection.rb', line 13 def self.load_data Utils.call_executable('--xml') end |
Instance Method Details
#[](id) ⇒ Interface
Returns traffic information for a certain interface.
50 51 52 53 54 55 |
# File 'lib/vnstat/interface_collection.rb', line 50 def [](id) interfaces_hash.fetch(id.to_s) do raise UnknownInterface.new(id.to_s), "Unknown interface: #{id}" end end |
#create(id) ⇒ Interface?
Creates the traffic database for the given interface.
71 72 73 74 75 76 77 |
# File 'lib/vnstat/interface_collection.rb', line 71 def create(id) success = Utils.call_executable_returning_status('--create', '-i', id) return nil unless success reload self[id] end |
#data=(data) ⇒ Object
Sets the raw XML data for the Vnstat::InterfaceCollection.
21 22 23 24 |
# File 'lib/vnstat/interface_collection.rb', line 21 def data=(data) super each { |interface| interface.data = data } end |
#each {|interface| ... } ⇒ Object
Iterates over each interface.
61 62 63 |
# File 'lib/vnstat/interface_collection.rb', line 61 def each(&block) interfaces_hash.each_value(&block) end |
#ids ⇒ Array<String>
Returns the names of known interfaces.
39 40 41 |
# File 'lib/vnstat/interface_collection.rb', line 39 def ids interfaces_hash.keys end |
#inspect ⇒ String
A human readable representation of the Vnstat::InterfaceCollection.
93 94 95 |
# File 'lib/vnstat/interface_collection.rb', line 93 def inspect "#<#{self.class.name} ids: #{ids.inspect}>" end |
#rebuild ⇒ InterfaceCollection
Reset the total traffic counters and recount those using recorded months.
83 84 85 86 87 |
# File 'lib/vnstat/interface_collection.rb', line 83 def rebuild success = Utils.call_executable_returning_status('--rebuildtotal') reload if success self end |
#reload ⇒ InterfaceCollection
Refreshes data cached in the current instance.
30 31 32 33 |
# File 'lib/vnstat/interface_collection.rb', line 30 def reload self.data = self.class.load_data self end |