class DNSSD::Flags

Flags used in DNSSD Ruby API.

Constants

ALL_FLAGS

Bitfield with all valid flags set

Public Class Methods

new(*flags) click to toggle source

Returns a new set of flags

# File lib/dnssd/flags.rb, line 33
def initialize(*flags)
  @flags = flags.inject 0 do |flag, acc| flag | acc end

  verify
end

Public Instance Methods

&(flags) click to toggle source

Returns the intersection of flags in self and flags.

# File lib/dnssd/flags.rb, line 42
def &(flags)
  self.class.new(to_i & flags.to_i)
end
==(other) click to toggle source

self is equal if other has the same flags

# File lib/dnssd/flags.rb, line 49
def ==(other)
  to_i == other.to_i
end
clear_flag(flag) click to toggle source

Clears flag

# File lib/dnssd/flags.rb, line 56
def clear_flag(flag)
  @flags &= ~flag

  verify
end
set_flag(flag) click to toggle source

Sets flag

# File lib/dnssd/flags.rb, line 71
def set_flag(flag)
  @flags |= flag

  verify
end
to_a() click to toggle source

Returns an Array of flag names

# File lib/dnssd/flags.rb, line 80
def to_a
  FLAGS.map do |name, value|
    (@flags & value == value) ? name : nil
  end.compact
end
to_i() click to toggle source

Flags as a bitfield

# File lib/dnssd/flags.rb, line 89
def to_i
  @flags
end
verify() click to toggle source

Trims the flag list down to valid flags

# File lib/dnssd/flags.rb, line 96
def verify
  @flags &= ALL_FLAGS

  self
end
|(flags) click to toggle source

Returns the union of flags in self and flags

# File lib/dnssd/flags.rb, line 105
def |(flags)
  self.class.new(to_i | flags.to_i)
end
~() click to toggle source

Returns the complement of the flags in self

# File lib/dnssd/flags.rb, line 112
def ~
  self.class.new ~to_i
end