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



92
93
94
# File 'lib/tree_haver/contracts.rb', line 92

def end_byte
  @end_byte
end

#start_byteObject

Returns the value of attribute start_byte

Returns:

  • (Object)

    the current value of 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

Returns:

  • (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

Returns:

  • (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

#lengthObject



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

Returns:

  • (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_hObject



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

Returns:

  • (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