Class: Ifconf::InterfaceFlags
- Inherits:
-
Object
- Object
- Ifconf::InterfaceFlags
- Defined in:
- lib/ifconf/interface_flags.rb
Overview
Represents the set of flags and MTU reported on an interface header line.
Constant Summary collapse
- KNOWN_FLAGS =
Set[ :up, :broadcast, :debug, :loopback, :pointopoint, :notrailers, :running, :noarp, :promisc, :allmulti, :master, :slave, :multicast, :portsel, :automedia, :dynamic, :lower_up, :dormant, :echo, :smart, :simplex ].freeze
Instance Attribute Summary collapse
-
#flags ⇒ Object
readonly
Returns the value of attribute flags.
-
#mtu ⇒ Object
readonly
Returns the value of attribute mtu.
-
#raw_value ⇒ Object
readonly
Returns the value of attribute raw_value.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #broadcast? ⇒ Boolean
- #flag?(flag) ⇒ Boolean
- #flag_names ⇒ Object
- #hash ⇒ Object
-
#initialize(flags, raw_value, mtu) ⇒ InterfaceFlags
constructor
A new instance of InterfaceFlags.
- #loopback? ⇒ Boolean
- #lower_up? ⇒ Boolean
- #multicast? ⇒ Boolean
- #noarp? ⇒ Boolean
- #operational? ⇒ Boolean
- #pointopoint? ⇒ Boolean
- #promisc? ⇒ Boolean
- #running? ⇒ Boolean
- #to_s ⇒ Object
- #up? ⇒ Boolean
Constructor Details
#initialize(flags, raw_value, mtu) ⇒ InterfaceFlags
Returns a new instance of InterfaceFlags.
26 27 28 29 30 31 32 33 |
# File 'lib/ifconf/interface_flags.rb', line 26 def initialize(flags, raw_value, mtu) raise Ifconf::Error, "mtu must be >= 0" unless mtu >= 0 @flags = flags.freeze @raw_value = raw_value @mtu = mtu freeze end |
Instance Attribute Details
#flags ⇒ Object (readonly)
Returns the value of attribute flags.
11 12 13 |
# File 'lib/ifconf/interface_flags.rb', line 11 def flags @flags end |
#mtu ⇒ Object (readonly)
Returns the value of attribute mtu.
11 12 13 |
# File 'lib/ifconf/interface_flags.rb', line 11 def mtu @mtu end |
#raw_value ⇒ Object (readonly)
Returns the value of attribute raw_value.
11 12 13 |
# File 'lib/ifconf/interface_flags.rb', line 11 def raw_value @raw_value end |
Class Method Details
.parse(raw_value, flag_names, mtu) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ifconf/interface_flags.rb', line 13 def self.parse(raw_value, flag_names, mtu) flags = Set.new flag_names.each do |name| sym = name.downcase.to_sym if KNOWN_FLAGS.include?(sym) flags << sym else warn "unknown flag: #{name}" end end new(flags, raw_value, mtu) end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
87 88 89 90 91 92 |
# File 'lib/ifconf/interface_flags.rb', line 87 def ==(other) other.is_a?(InterfaceFlags) && @flags == other.flags && @raw_value == other.raw_value && @mtu == other.mtu end |
#broadcast? ⇒ Boolean
39 40 41 |
# File 'lib/ifconf/interface_flags.rb', line 39 def broadcast? @flags.include?(:broadcast) end |
#flag?(flag) ⇒ Boolean
71 72 73 |
# File 'lib/ifconf/interface_flags.rb', line 71 def flag?(flag) @flags.include?(flag) end |
#flag_names ⇒ Object
79 80 81 |
# File 'lib/ifconf/interface_flags.rb', line 79 def flag_names @flags.to_a end |
#hash ⇒ Object
96 97 98 |
# File 'lib/ifconf/interface_flags.rb', line 96 def hash [@flags, @raw_value, @mtu].hash end |
#loopback? ⇒ Boolean
51 52 53 |
# File 'lib/ifconf/interface_flags.rb', line 51 def loopback? @flags.include?(:loopback) end |
#lower_up? ⇒ Boolean
67 68 69 |
# File 'lib/ifconf/interface_flags.rb', line 67 def lower_up? @flags.include?(:lower_up) end |
#multicast? ⇒ Boolean
47 48 49 |
# File 'lib/ifconf/interface_flags.rb', line 47 def multicast? @flags.include?(:multicast) end |
#noarp? ⇒ Boolean
59 60 61 |
# File 'lib/ifconf/interface_flags.rb', line 59 def noarp? @flags.include?(:noarp) end |
#operational? ⇒ Boolean
75 76 77 |
# File 'lib/ifconf/interface_flags.rb', line 75 def operational? up? && running? end |
#pointopoint? ⇒ Boolean
63 64 65 |
# File 'lib/ifconf/interface_flags.rb', line 63 def pointopoint? @flags.include?(:pointopoint) end |
#promisc? ⇒ Boolean
55 56 57 |
# File 'lib/ifconf/interface_flags.rb', line 55 def promisc? @flags.include?(:promisc) end |
#running? ⇒ Boolean
43 44 45 |
# File 'lib/ifconf/interface_flags.rb', line 43 def running? @flags.include?(:running) end |
#to_s ⇒ Object
83 84 85 |
# File 'lib/ifconf/interface_flags.rb', line 83 def to_s "<#{@flags.map { |f| f.to_s.upcase }.join(",")}>" end |
#up? ⇒ Boolean
35 36 37 |
# File 'lib/ifconf/interface_flags.rb', line 35 def up? @flags.include?(:up) end |