Class: Tus::Info

Inherits:
Object
  • Object
show all
Defined in:
lib/tus/info.rb

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.



16
17
18
# File 'lib/tus/info.rb', line 16

def initialize(hash)
  @hash = hash
end

Instance Method Details

#[](key) ⇒ Object



20
21
22
# File 'lib/tus/info.rb', line 20

def [](key)
  @hash[key]
end

#[]=(key, value) ⇒ Object



24
25
26
# File 'lib/tus/info.rb', line 24

def []=(key, value)
  @hash[key] = value
end

#concatenation?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/tus/info.rb', line 52

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

#defer_length?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/tus/info.rb', line 56

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

#expiresObject



48
49
50
# File 'lib/tus/info.rb', line 48

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

#headersObject



32
33
34
# File 'lib/tus/info.rb', line 32

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

#lengthObject



36
37
38
# File 'lib/tus/info.rb', line 36

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

#metadataObject



44
45
46
# File 'lib/tus/info.rb', line 44

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

#offsetObject



40
41
42
# File 'lib/tus/info.rb', line 40

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

#partial_uploadsObject



60
61
62
63
# File 'lib/tus/info.rb', line 60

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

#remaining_lengthObject



65
66
67
# File 'lib/tus/info.rb', line 65

def remaining_length
  length - offset
end

#to_hObject



28
29
30
# File 'lib/tus/info.rb', line 28

def to_h
  @hash
end