Class: Rstreamor::Request
- Inherits:
-
Object
- Object
- Rstreamor::Request
- Defined in:
- lib/rstreamor/request.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Instance Method Summary collapse
- #file_content_type ⇒ Object
- #file_size ⇒ Object
-
#initialize(request, file) ⇒ Request
constructor
A new instance of Request.
- #lower_bound ⇒ Object
- #range_header? ⇒ Boolean
- #ranges ⇒ Object
- #slice_file ⇒ Object
- #upper_bound ⇒ Object
Constructor Details
#initialize(request, file) ⇒ Request
Returns a new instance of Request.
5 6 7 8 |
# File 'lib/rstreamor/request.rb', line 5 def initialize(request, file) @request = request @file = file end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
3 4 5 |
# File 'lib/rstreamor/request.rb', line 3 def file @file end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
3 4 5 |
# File 'lib/rstreamor/request.rb', line 3 def request @request end |
Instance Method Details
#file_content_type ⇒ Object
26 27 28 |
# File 'lib/rstreamor/request.rb', line 26 def file_content_type file.content_type end |
#file_size ⇒ Object
38 39 40 |
# File 'lib/rstreamor/request.rb', line 38 def file_size file.size end |
#lower_bound ⇒ Object
18 19 20 |
# File 'lib/rstreamor/request.rb', line 18 def lower_bound ranges[0] ? ranges[0].to_i : 0 end |
#range_header? ⇒ Boolean
22 23 24 |
# File 'lib/rstreamor/request.rb', line 22 def range_header? request.headers['HTTP_RANGE'].present? end |
#ranges ⇒ Object
10 11 12 |
# File 'lib/rstreamor/request.rb', line 10 def ranges request.headers['HTTP_RANGE'].gsub('bytes=', '').split('-') if request.headers['HTTP_RANGE'] end |
#slice_file ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/rstreamor/request.rb', line 30 def slice_file if request.headers['HTTP_RANGE'].present? file.data.byteslice(lower_bound..upper_bound) else file.data end end |
#upper_bound ⇒ Object
14 15 16 |
# File 'lib/rstreamor/request.rb', line 14 def upper_bound ranges[1] ? ranges[1].to_i : (file.size - 1) end |