-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from tomascco:chore/improve-tests
Improve tests and refactor
- Loading branch information
Showing
15 changed files
with
379 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# typed: true | ||
# frozen_string_literal: true | ||
|
||
module Rubrik | ||
class Document | ||
module SerializeObject | ||
include Kernel | ||
extend T::Sig | ||
extend self | ||
|
||
sig {params(obj: T.untyped).returns(String)} | ||
def [](obj) | ||
case obj | ||
when Hash | ||
serialized_objs = obj.flatten.map { |e| SerializeObject[e] } | ||
"<<#{serialized_objs.join(" ")}>>" | ||
when 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 | ||
"(#{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 | ||
|
||
alias call [] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.