Class: Tus::Info
- Inherits:
-
Object
- Object
- Tus::Info
- 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
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #concatenation? ⇒ Boolean
- #defer_length? ⇒ Boolean
- #expires ⇒ Object
- #headers ⇒ Object
-
#initialize(hash) ⇒ Info
constructor
A new instance of Info.
- #length ⇒ Object
- #metadata ⇒ Object
- #offset ⇒ Object
- #partial_uploads ⇒ Object
- #remaining_length ⇒ Object
- #to_h ⇒ Object
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
52 53 54 |
# File 'lib/tus/info.rb', line 52 def concatenation? @hash["Upload-Concat"].to_s.start_with?("final") end |
#defer_length? ⇒ Boolean
56 57 58 |
# File 'lib/tus/info.rb', line 56 def defer_length? @hash["Upload-Defer-Length"] == "1" end |
#expires ⇒ Object
48 49 50 |
# File 'lib/tus/info.rb', line 48 def expires Time.parse(@hash["Upload-Expires"]) end |
#headers ⇒ Object
32 33 34 |
# File 'lib/tus/info.rb', line 32 def headers @hash.select { |key, value| HEADERS.include?(key) && !value.nil? } end |
#length ⇒ Object
36 37 38 |
# File 'lib/tus/info.rb', line 36 def length Integer(@hash["Upload-Length"]) if @hash["Upload-Length"] end |
#metadata ⇒ Object
44 45 46 |
# File 'lib/tus/info.rb', line 44 def (@hash["Upload-Metadata"]) end |
#offset ⇒ Object
40 41 42 |
# File 'lib/tus/info.rb', line 40 def offset Integer(@hash["Upload-Offset"]) end |
#partial_uploads ⇒ Object
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_length ⇒ Object
65 66 67 |
# File 'lib/tus/info.rb', line 65 def remaining_length length - offset end |
#to_h ⇒ Object
28 29 30 |
# File 'lib/tus/info.rb', line 28 def to_h @hash end |