Class: Tus::Info
- Inherits:
-
Object
- Object
- Tus::Info
- Defined in:
- lib/tus/info.rb
Overview
Holds request headers and other information about tus uploads.
Constant Summary collapse
- HEADERS =
%w[ Upload-Length Upload-Offset Upload-Defer-Length Upload-Metadata Upload-Concat Upload-Expires ]
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #defer_length? ⇒ Boolean
- #expires ⇒ Object
- #final? ⇒ Boolean
- #headers ⇒ Object
-
#initialize(hash) ⇒ Info
constructor
A new instance of Info.
- #length ⇒ Object
- #metadata ⇒ Object
- #name ⇒ Object
- #offset ⇒ Object
- #partial? ⇒ Boolean
- #partial_uploads ⇒ Object
- #remaining_length ⇒ Object
- #to_h ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(hash) ⇒ Info
Returns a new instance of Info.
18 19 20 |
# File 'lib/tus/info.rb', line 18 def initialize(hash) @hash = hash end |
Instance Method Details
#[](key) ⇒ Object
22 23 24 |
# File 'lib/tus/info.rb', line 22 def [](key) @hash[key] end |
#[]=(key, value) ⇒ Object
26 27 28 |
# File 'lib/tus/info.rb', line 26 def []=(key, value) @hash[key] = value end |
#defer_length? ⇒ Boolean
75 76 77 |
# File 'lib/tus/info.rb', line 75 def defer_length? @hash["Upload-Defer-Length"] == "1" end |
#expires ⇒ Object
58 59 60 |
# File 'lib/tus/info.rb', line 58 def expires Time.parse(@hash["Upload-Expires"]) end |
#final? ⇒ Boolean
66 67 68 |
# File 'lib/tus/info.rb', line 66 def final? @hash["Upload-Concat"].to_s.start_with?("final") end |
#headers ⇒ Object
34 35 36 |
# File 'lib/tus/info.rb', line 34 def headers @hash.select { |key, value| HEADERS.include?(key) && !value.nil? } end |
#length ⇒ Object
38 39 40 |
# File 'lib/tus/info.rb', line 38 def length Integer(@hash["Upload-Length"]) if @hash["Upload-Length"] end |
#metadata ⇒ Object
46 47 48 |
# File 'lib/tus/info.rb', line 46 def (@hash["Upload-Metadata"]) end |
#name ⇒ Object
50 51 52 |
# File 'lib/tus/info.rb', line 50 def name ["name"] || ["filename"] end |
#offset ⇒ Object
42 43 44 |
# File 'lib/tus/info.rb', line 42 def offset Integer(@hash["Upload-Offset"]) if @hash["Upload-Offset"] end |
#partial? ⇒ Boolean
62 63 64 |
# File 'lib/tus/info.rb', line 62 def partial? @hash["Upload-Concat"] == "partial" end |
#partial_uploads ⇒ Object
70 71 72 73 |
# File 'lib/tus/info.rb', line 70 def partial_uploads urls = @hash["Upload-Concat"].split(";").last.split(" ") urls.map { |url| url.split("/").last } end |
#remaining_length ⇒ Object
79 80 81 |
# File 'lib/tus/info.rb', line 79 def remaining_length length - offset end |
#to_h ⇒ Object
30 31 32 |
# File 'lib/tus/info.rb', line 30 def to_h @hash end |
#type ⇒ Object
54 55 56 |
# File 'lib/tus/info.rb', line 54 def type ["type"] || ["content_type"] end |