Module: XmpToolkitRuby::XmpFileOpenFlags

Defined in:
lib/xmp_toolkit_ruby/xmp_file_open_flags.rb

Constant Summary collapse

OPEN_FOR_READ =

Open for read-only access

0x0000_0001
OPEN_FOR_UPDATE =

Open for reading and writing

0x0000_0002
OPEN_ONLY_XMP =

Only the XMP is wanted, allows space/time optimizations

0x0000_0004
FORCE_GIVEN_HANDLER =

Force use of the given handler (format), do not verify format

0x0000_0008
OPEN_STRICTLY =

Strictly use only designated file handler, no fallback

0x0000_0010
OPEN_USE_SMART_HANDLER =

Require the use of a smart handler

0x0000_0020
OPEN_USE_PACKET_SCANNING =

Force packet scanning, do not use smart handler

0x0000_0040
OPEN_LIMITED_SCANNING =

Only scan files “known” to need scanning

0x0000_0080
OPEN_REPAIR_FILE =

Attempt to repair a file opened for update

0x0000_0100
OPTIMIZE_FILE_LAYOUT =

Optimize file layout when updating

0x0000_0200
PRESERVE_PDF_STATE =

Preserve PDF document state when updating

0x0000_0400
FLAGS =
{
  open_for_read: OPEN_FOR_READ,
  open_for_update: OPEN_FOR_UPDATE,
  open_only_xmp: OPEN_ONLY_XMP,
  force_given_handler: FORCE_GIVEN_HANDLER,
  open_strictly: OPEN_STRICTLY,
  open_use_smart_handler: OPEN_USE_SMART_HANDLER,
  open_use_packet_scanning: OPEN_USE_PACKET_SCANNING,
  open_limited_scanning: OPEN_LIMITED_SCANNING,
  open_repair_file: OPEN_REPAIR_FILE,
  optimize_file_layout: OPTIMIZE_FILE_LAYOUT,
  preserve_pdf_state: PRESERVE_PDF_STATE
}.freeze
FLAGS_BY_VALUE =
FLAGS.invert.freeze

Class Method Summary collapse

Class Method Details

.bitmask_for(*args) ⇒ Object

Takes multiple flag names (symbols or strings) or constants, returns combined bitmask OR-ing all.

Example:

bitmask_for(:open_for_read, :force_given_handler)
bitmask_for(OPEN_FOR_READ, FORCE_GIVEN_HANDLER)


59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/xmp_toolkit_ruby/xmp_file_open_flags.rb', line 59

def bitmask_for(*args)
  args.reduce(0) do |mask, flag|
    val = case flag
          when Symbol, String then value_for(flag)
          when Integer then flag
          else
            raise ArgumentError, "Invalid flag type: #{flag.class}"
          end
    raise ArgumentError, "Unknown flag: #{flag.inspect}" unless val

    mask | val
  end
end

.contains?(bitmask, flag) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (ArgumentError)


47
48
49
50
51
# File 'lib/xmp_toolkit_ruby/xmp_file_open_flags.rb', line 47

def contains?(bitmask, flag)
  raise ArgumentError, "Invalid flag type: #{flag.class}" unless flag.is_a?(Symbol) || flag.is_a?(String)

  bitmask & value_for(flag) != 0
end

.flags_for(bitmask) ⇒ Object



43
44
45
# File 'lib/xmp_toolkit_ruby/xmp_file_open_flags.rb', line 43

def flags_for(bitmask)
  FLAGS.select { |_, bit| bitmask.anybits?(bit) }.keys
end

.name_for(hex_value) ⇒ Object



39
40
41
# File 'lib/xmp_toolkit_ruby/xmp_file_open_flags.rb', line 39

def name_for(hex_value)
  FLAGS_BY_VALUE[hex_value]
end

.value_for(name) ⇒ Object



34
35
36
37
# File 'lib/xmp_toolkit_ruby/xmp_file_open_flags.rb', line 34

def value_for(name)
  key = name.is_a?(String) ? name.to_sym : name
  FLAGS[key]
end