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.
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
51 52 53 |
# File 'lib/tus/info.rb', line 51 def concatenation? @hash["Upload-Concat"].to_s.start_with?("final") end |
#defer_length? ⇒ Boolean
55 56 57 |
# File 'lib/tus/info.rb', line 55 def defer_length? @hash["Upload-Defer-Length"] == "1" end |
#expires ⇒ Object
47 48 49 |
# File 'lib/tus/info.rb', line 47 def expires Time.parse(@hash["Upload-Expires"]) end |
#headers ⇒ Object
31 32 33 |
# File 'lib/tus/info.rb', line 31 def headers @hash.select { |key, value| HEADERS.include?(key) && !value.nil? } end |
#length ⇒ Object
35 36 37 |
# File 'lib/tus/info.rb', line 35 def length Integer(@hash["Upload-Length"]) if @hash["Upload-Length"] end |
#metadata ⇒ Object
43 44 45 |
# File 'lib/tus/info.rb', line 43 def (@hash["Upload-Metadata"]) end |
#offset ⇒ Object
39 40 41 |
# File 'lib/tus/info.rb', line 39 def offset Integer(@hash["Upload-Offset"]) end |
#partial_uploads ⇒ Object
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_length ⇒ Object
64 65 66 |
# File 'lib/tus/info.rb', line 64 def remaining_length length - offset end |
#to_h ⇒ Object
27 28 29 |
# File 'lib/tus/info.rb', line 27 def to_h @hash end |