module HexaPDF::Utils::BitField

This module is intended to be used to extend class objects. It provides the method bit_field for declaring a bit field.

Public Instance Methods

bit_field(name, mapping, lister: "

Creates a bit field for managing the integer attribute name.

The mapping argument specifies the mapping of names to bit indices which allows one to use either the bit name or its index when getting or setting. When using an unknown bit name or bit index, an error is raised.

The calling class needs to respond to #name and #name= because these methods are used to get and set the raw integer value.

After invoking the method the calling class has three new instance methods:

  • NAME_values which returns an array of bit names representing the set bits.

  • NAME_include?(bit) which returns true if the given bit is set.

  • set_NAME(*bits, clear_existing: false) for setting the given bits.

The method names can be overridden using the arguments lister, getter and setter.