Class: Tus::Info

Inherits:
Object
  • Object
show all
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

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

Returns:

  • (Boolean)


67
68
69
# File 'lib/tus/info.rb', line 67

def defer_length?
  @hash["Upload-Defer-Length"] == "1"
end

#expiresObject



50
51
52
# File 'lib/tus/info.rb', line 50

def expires
  Time.parse(@hash["Upload-Expires"])
end

#final?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/tus/info.rb', line 58

def final?
  @hash["Upload-Concat"].to_s.start_with?("final")
end

#headersObject



34
35
36
# File 'lib/tus/info.rb', line 34

def headers
  @hash.select { |key, value| HEADERS.include?(key) && !value.nil? }
end

#lengthObject



38
39
40
# File 'lib/tus/info.rb', line 38

def length
  Integer(@hash["Upload-Length"]) if @hash["Upload-Length"]
end

#metadataObject



46
47
48
# File 'lib/tus/info.rb', line 46

def 
  (@hash["Upload-Metadata"])
end

#offsetObject



42
43
44
# File 'lib/tus/info.rb', line 42

def offset
  Integer(@hash["Upload-Offset"])
end

#partial?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/tus/info.rb', line 54

def partial?
  @hash["Upload-Concat"] == "partial"
end

#partial_uploadsObject



62
63
64
65
# File 'lib/tus/info.rb', line 62

def partial_uploads
  urls = @hash["Upload-Concat"].split(";").last.split(" ")
  urls.map { |url| url.split("/").last }
end

#remaining_lengthObject



71
72
73
# File 'lib/tus/info.rb', line 71

def remaining_length
  length - offset
end

#to_hObject



30
31
32
# File 'lib/tus/info.rb', line 30

def to_h
  @hash
end