Class: CIFS::RangeHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/jcifs.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (RangeHelper) initialize(spec, length)

spec

'x-y', 'x-' or '-y', see RFC 2616 14.35.1

length

the Content-Length



227
228
229
230
231
232
233
234
235
236
237
# File 'lib/jcifs.rb', line 227

def initialize(spec, length)
    @spec = spec
    @vals = spec.split('-').map{ |x| x.empty? ? nil : x.to_i }
    @length = length
    @first = create_first
    @last  = create_last
    if @first > @last
        raise RangeNotSatisfiableException, \
            "invalid spec #{ @spec } first #{@first} last #{@last} length #{@length}"
    end
end

Instance Attribute Details

- (Object) first (readonly)

Returns the value of attribute first



223
224
225
# File 'lib/jcifs.rb', line 223

def first
  @first
end

- (Object) last (readonly)

Returns the value of attribute last



223
224
225
# File 'lib/jcifs.rb', line 223

def last
  @last
end

Instance Method Details

- (Object) content_range

returns the value for the HTTP Content-Range header



264
265
266
# File 'lib/jcifs.rb', line 264

def content_range
    "%d-%d/%d" % [self.first, self.last, @length]
end

- (Object) to_read

how much bytes must be read for this range



269
270
271
# File 'lib/jcifs.rb', line 269

def to_read
    @last - @first + 1
end