Class: Ifconf::InterfaceFlags

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(flags, raw_value, mtu) ⇒ InterfaceFlags

Returns a new instance of InterfaceFlags.

Raises:



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

#flagsObject (readonly)

Returns the value of attribute flags.



11
12
13
# File 'lib/ifconf/interface_flags.rb', line 11

def flags
  @flags
end

#mtuObject (readonly)

Returns the value of attribute mtu.



11
12
13
# File 'lib/ifconf/interface_flags.rb', line 11

def mtu
  @mtu
end

#raw_valueObject (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

Returns:

  • (Boolean)


39
40
41
# File 'lib/ifconf/interface_flags.rb', line 39

def broadcast?
  @flags.include?(:broadcast)
end

#flag?(flag) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/ifconf/interface_flags.rb', line 71

def flag?(flag)
  @flags.include?(flag)
end

#flag_namesObject



79
80
81
# File 'lib/ifconf/interface_flags.rb', line 79

def flag_names
  @flags.to_a
end

#hashObject



96
97
98
# File 'lib/ifconf/interface_flags.rb', line 96

def hash
  [@flags, @raw_value, @mtu].hash
end

#loopback?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/ifconf/interface_flags.rb', line 51

def loopback?
  @flags.include?(:loopback)
end

#lower_up?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/ifconf/interface_flags.rb', line 67

def lower_up?
  @flags.include?(:lower_up)
end

#multicast?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/ifconf/interface_flags.rb', line 47

def multicast?
  @flags.include?(:multicast)
end

#noarp?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/ifconf/interface_flags.rb', line 59

def noarp?
  @flags.include?(:noarp)
end

#operational?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/ifconf/interface_flags.rb', line 75

def operational?
  up? && running?
end

#pointopoint?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/ifconf/interface_flags.rb', line 63

def pointopoint?
  @flags.include?(:pointopoint)
end

#promisc?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/ifconf/interface_flags.rb', line 55

def promisc?
  @flags.include?(:promisc)
end

#running?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/ifconf/interface_flags.rb', line 43

def running?
  @flags.include?(:running)
end

#to_sObject



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

Returns:

  • (Boolean)


35
36
37
# File 'lib/ifconf/interface_flags.rb', line 35

def up?
  @flags.include?(:up)
end