Class: TreeHaver::ByteRange
- Inherits:
-
Struct
- Object
- Struct
- TreeHaver::ByteRange
- Defined in:
- lib/tree_haver/contracts.rb
Instance Attribute Summary collapse
-
#end_byte ⇒ Object
Returns the value of attribute end_byte.
-
#start_byte ⇒ Object
Returns the value of attribute start_byte.
Instance Method Summary collapse
- #contains_byte?(offset) ⇒ Boolean
- #contains_range?(other) ⇒ Boolean
- #length ⇒ Object
- #overlaps?(other) ⇒ Boolean
- #to_h ⇒ Object
- #valid? ⇒ Boolean
Instance Attribute Details
#end_byte ⇒ Object
Returns the value of attribute end_byte
286 287 288 |
# File 'lib/tree_haver/contracts.rb', line 286 def end_byte @end_byte end |
#start_byte ⇒ Object
Returns the value of attribute 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
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
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 |
#length ⇒ Object
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
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_h ⇒ Object
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
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 |