class Tus::Info
Holds request headers and other information about tus uploads.
Constants
- HEADERS
Public Class Methods
new(hash)
click to toggle source
# File lib/tus/info.rb, line 18 def initialize(hash) @hash = hash end
Public Instance Methods
[](key)
click to toggle source
# File lib/tus/info.rb, line 22 def [](key) @hash[key] end
[]=(key, value)
click to toggle source
# File lib/tus/info.rb, line 26 def []=(key, value) @hash[key] = value end
defer_length?()
click to toggle source
# File lib/tus/info.rb, line 75 def defer_length? @hash["Upload-Defer-Length"] == "1" end
expires()
click to toggle source
# File lib/tus/info.rb, line 58 def expires Time.parse(@hash["Upload-Expires"]) end
final?()
click to toggle source
# File lib/tus/info.rb, line 66 def final? @hash["Upload-Concat"].to_s.start_with?("final") end
headers()
click to toggle source
# File lib/tus/info.rb, line 34 def headers @hash.select { |key, value| HEADERS.include?(key) && !value.nil? } end
length()
click to toggle source
# File lib/tus/info.rb, line 38 def length Integer(@hash["Upload-Length"]) if @hash["Upload-Length"] end
metadata()
click to toggle source
# File lib/tus/info.rb, line 46 def metadata parse_metadata(@hash["Upload-Metadata"]) end
name()
click to toggle source
# File lib/tus/info.rb, line 50 def name metadata["name"] || metadata["filename"] end
offset()
click to toggle source
# File lib/tus/info.rb, line 42 def offset Integer(@hash["Upload-Offset"]) if @hash["Upload-Offset"] end
partial?()
click to toggle source
# File lib/tus/info.rb, line 62 def partial? @hash["Upload-Concat"] == "partial" end
partial_uploads()
click to toggle source
# 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()
click to toggle source
# File lib/tus/info.rb, line 79 def remaining_length length - offset end
to_h()
click to toggle source
# File lib/tus/info.rb, line 30 def to_h @hash end
type()
click to toggle source
# File lib/tus/info.rb, line 54 def type metadata["type"] || metadata["content_type"] end
Private Instance Methods
parse_metadata(string)
click to toggle source
# File lib/tus/info.rb, line 85 def parse_metadata(string) return {} if string == nil || string == "" pairs = string.split(",").map { |s| s.split(" ") } hash = Hash[pairs] hash.each do |key, value| hash[key] = value && Base64.decode64(value) end hash end