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
92 93 94 |
# File 'lib/tree_haver/contracts.rb', line 92 def end_byte @end_byte end |
#start_byte ⇒ Object
Returns the value of attribute start_byte
92 93 94 |
# File 'lib/tree_haver/contracts.rb', line 92 def start_byte @start_byte end |
Instance Method Details
#contains_byte?(offset) ⇒ Boolean
101 102 103 |
# File 'lib/tree_haver/contracts.rb', line 101 def contains_byte?(offset) valid? && offset.to_i >= start_byte.to_i && offset.to_i < end_byte.to_i end |
#contains_range?(other) ⇒ Boolean
105 106 107 |
# File 'lib/tree_haver/contracts.rb', line 105 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
97 98 99 |
# File 'lib/tree_haver/contracts.rb', line 97 def length valid? ? end_byte.to_i - start_byte.to_i : 0 end |
#overlaps?(other) ⇒ Boolean
109 110 111 |
# File 'lib/tree_haver/contracts.rb', line 109 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
113 114 115 116 117 118 |
# File 'lib/tree_haver/contracts.rb', line 113 def to_h { start_byte: start_byte, end_byte: end_byte } end |
#valid? ⇒ Boolean
93 94 95 |
# File 'lib/tree_haver/contracts.rb', line 93 def valid? start_byte.to_i >= 0 && end_byte.to_i >= start_byte.to_i end |