Class: Ifconfig
- Inherits:
-
Object
- Object
- Ifconfig
- Defined in:
- lib/Unix/Ifconfig.rb
Instance Attribute Summary collapse
-
#interfaces ⇒ Object
readonly
Returns the value of attribute interfaces.
-
#interfaces_raw ⇒ Object
readonly
Returns the value of attribute interfaces_raw.
-
#string_raw ⇒ Object
readonly
Returns the value of attribute string_raw.
Instance Method Summary collapse
-
#initialize(string = '') ⇒ Ifconfig
constructor
A new instance of Ifconfig.
- #parse(string) ⇒ Object
Constructor Details
Instance Attribute Details
#interfaces ⇒ Object (readonly)
Returns the value of attribute interfaces.
7 8 9 |
# File 'lib/Unix/Ifconfig.rb', line 7 def interfaces @interfaces end |
#interfaces_raw ⇒ Object (readonly)
Returns the value of attribute interfaces_raw.
6 7 8 |
# File 'lib/Unix/Ifconfig.rb', line 6 def interfaces_raw @interfaces_raw end |
#string_raw ⇒ Object (readonly)
Returns the value of attribute string_raw.
5 6 7 |
# File 'lib/Unix/Ifconfig.rb', line 5 def string_raw @string_raw end |
Instance Method Details
#parse(string) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/Unix/Ifconfig.rb', line 15 def parse(string) @string_raw = string interface_raw = '' string.each_line do |line| next if (line =~ /^\s*$/) if (line =~ /^\w+\d+:/) @interfaces_raw.push(interface_raw) unless interface_raw.empty? interface_raw = line else interface_raw += line + "\n" end end @interfaces_raw.push(interface_raw) unless interface_raw.empty? @interfaces_raw.each do |string| interface = Ifconfig_interface.new(string) @interfaces[interface.name] = interface end end |