Class: Tus::Info

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

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Info

Returns a new instance of Info.



6
7
8
# File 'lib/tus/info.rb', line 6

def initialize(hash)
  @hash = hash
end

Instance Method Details

#[](key) ⇒ Object



10
11
12
# File 'lib/tus/info.rb', line 10

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

#[]=(key, value) ⇒ Object



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

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

#defer_length?Boolean

Returns:

  • (Boolean)


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

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

#expiresObject



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

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

#final_upload?Boolean

Returns:

  • (Boolean)


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

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

#lengthObject



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

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

#metadataObject



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

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

#offsetObject



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

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

#partial_uploadsObject



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

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

#remaining_lengthObject



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

def remaining_length
  length - offset
end

#to_hObject



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

def to_h
  @hash.reject { |key, value| value.nil? }
end