Class: Tus::Info
- Inherits:
-
Object
- Object
- Tus::Info
- Defined in:
- lib/tus/info.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #defer_length? ⇒ Boolean
- #expires ⇒ Object
- #final_upload? ⇒ Boolean
-
#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.
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
42 43 44 |
# File 'lib/tus/info.rb', line 42 def defer_length? @hash["Upload-Defer-Length"] == "1" end |
#expires ⇒ Object
34 35 36 |
# File 'lib/tus/info.rb', line 34 def expires Time.parse(@hash["Upload-Expires"]) end |
#final_upload? ⇒ Boolean
38 39 40 |
# File 'lib/tus/info.rb', line 38 def final_upload? @hash["Upload-Concat"].to_s.start_with?("final") end |
#length ⇒ Object
22 23 24 |
# File 'lib/tus/info.rb', line 22 def length Integer(@hash["Upload-Length"]) end |
#metadata ⇒ Object
30 31 32 |
# File 'lib/tus/info.rb', line 30 def (@hash["Upload-Metadata"]) end |
#offset ⇒ Object
26 27 28 |
# File 'lib/tus/info.rb', line 26 def offset Integer(@hash["Upload-Offset"]) end |
#partial_uploads ⇒ Object
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_length ⇒ Object
51 52 53 |
# File 'lib/tus/info.rb', line 51 def remaining_length length - offset end |
#to_h ⇒ Object
18 19 20 |
# File 'lib/tus/info.rb', line 18 def to_h @hash.reject { |key, value| value.nil? } end |