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.



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

def initialize(hash)
  @hash = hash
end

Instance Method Details

#[](key) ⇒ Object



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

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

#[]=(key, value) ⇒ Object



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

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

#concatenation?Boolean

Returns:

  • (Boolean)


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

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

#defer_length?Boolean

Returns:

  • (Boolean)


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

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

#expiresObject



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

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

#headersObject



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

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

#lengthObject



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

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

#metadataObject



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

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

#offsetObject



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

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

#partial_uploadsObject



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

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

#remaining_lengthObject



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

def remaining_length
  length - offset
end

#to_hObject



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

def to_h
  @hash
end