Module: Rubrik::Document::SerializeObject

Extended by:
SerializeObject, T::Sig
Includes:
Kernel
Included in:
SerializeObject
Defined in:
lib/rubrik/document/serialize_object.rb

Instance Method Summary collapse

Instance Method Details

#[](obj) ⇒ Object Also known as: call



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rubrik/document/serialize_object.rb', line 12

def [](obj)
  case obj
  when Hash
    serialized_objs = obj.flatten.map { |e| SerializeObject[e] }
    "<<#{serialized_objs.join(" ")}>>"
  when Symbol
    serialize_symbol(obj)
  when Array
    serialized_objs = obj.map { |e| SerializeObject[e] }
    "[#{serialized_objs.join(" ")}]"
  when PDF::Reader::Reference
    "#{obj.id} #{obj.gen} R"
  when String
    serialize_string(obj)
  when TrueClass
    "true"
  when FalseClass
    "false"
  when Document::CONTENTS_PLACEHOLDER
    "<#{"0" * Document::SIGNATURE_SIZE}>"
  when Document::BYTE_RANGE_PLACEHOLDER
    "[0 0000000000 0000000000 0000000000]"
  when Float, Integer
    obj.to_s
  when NilClass
    "null"
  when PDF::Reader::Stream
    <<~OBJECT.chomp
      #{SerializeObject[obj.hash]}
      stream
      #{obj.data}
      endstream
    OBJECT
  else
    raise "Don't know how to serialize #{obj}"
  end
end