Class: TreeHaver::ByteRange

Inherits:
Struct
  • Object
show all
Defined in:
lib/tree_haver/contracts.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#end_byteObject

Returns the value of attribute end_byte

Returns:

  • (Object)

    the current value of end_byte



286
287
288
# File 'lib/tree_haver/contracts.rb', line 286

def end_byte
  @end_byte
end

#start_byteObject

Returns the value of attribute start_byte

Returns:

  • (Object)

    the current value of start_byte



286
287
288
# File 'lib/tree_haver/contracts.rb', line 286

def start_byte
  @start_byte
end

Instance Method Details

#contains_byte?(offset) ⇒ Boolean

Returns:

  • (Boolean)


295
296
297
# File 'lib/tree_haver/contracts.rb', line 295

def contains_byte?(offset)
  valid? && offset.to_i >= start_byte.to_i && offset.to_i < end_byte.to_i
end

#contains_range?(other) ⇒ Boolean

Returns:

  • (Boolean)


299
300
301
# File 'lib/tree_haver/contracts.rb', line 299

def contains_range?(other)
  valid? && other.valid? && other.start_byte.to_i >= start_byte.to_i && other.end_byte.to_i <= end_byte.to_i
end

#lengthObject



291
292
293
# File 'lib/tree_haver/contracts.rb', line 291

def length
  valid? ? end_byte.to_i - start_byte.to_i : 0
end

#overlaps?(other) ⇒ Boolean

Returns:

  • (Boolean)


303
304
305
# File 'lib/tree_haver/contracts.rb', line 303

def overlaps?(other)
  valid? && other.valid? && start_byte.to_i < other.end_byte.to_i && other.start_byte.to_i < end_byte.to_i
end

#to_hObject



307
308
309
310
311
312
# File 'lib/tree_haver/contracts.rb', line 307

def to_h
  {
    start_byte: start_byte,
    end_byte: end_byte
  }
end

#valid?Boolean

Returns:

  • (Boolean)


287
288
289
# File 'lib/tree_haver/contracts.rb', line 287

def valid?
  start_byte.to_i >= 0 && end_byte.to_i >= start_byte.to_i
end