Class: Engram::Provenance::Span
- Inherits:
-
Object
- Object
- Engram::Provenance::Span
- Defined in:
- lib/engram/provenance.rb
Constant Summary collapse
- OFFSET_UNIT =
"unicode_codepoint"
Instance Attribute Summary collapse
-
#end_offset ⇒ Object
readonly
Returns the value of attribute end_offset.
-
#offset_unit ⇒ Object
readonly
Returns the value of attribute offset_unit.
-
#start_offset ⇒ Object
readonly
Returns the value of attribute start_offset.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #end_exclusive? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(start_offset:, end_offset:, offset_unit: OFFSET_UNIT) ⇒ Span
constructor
A new instance of Span.
- #to_h ⇒ Object
Constructor Details
#initialize(start_offset:, end_offset:, offset_unit: OFFSET_UNIT) ⇒ Span
Returns a new instance of Span.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/engram/provenance.rb', line 20 def initialize(start_offset:, end_offset:, offset_unit: OFFSET_UNIT) unless start_offset.is_a?(Integer) && end_offset.is_a?(Integer) && start_offset >= 0 && end_offset > start_offset raise ArgumentError, "span offsets must be non-negative integers with end_offset > start_offset" end raise ArgumentError, "unsupported offset unit" unless offset_unit.to_s == OFFSET_UNIT @start_offset = start_offset @end_offset = end_offset @offset_unit = OFFSET_UNIT freeze end |
Instance Attribute Details
#end_offset ⇒ Object (readonly)
Returns the value of attribute end_offset.
18 19 20 |
# File 'lib/engram/provenance.rb', line 18 def end_offset @end_offset end |
#offset_unit ⇒ Object (readonly)
Returns the value of attribute offset_unit.
18 19 20 |
# File 'lib/engram/provenance.rb', line 18 def offset_unit @offset_unit end |
#start_offset ⇒ Object (readonly)
Returns the value of attribute start_offset.
18 19 20 |
# File 'lib/engram/provenance.rb', line 18 def start_offset @start_offset end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
35 36 37 |
# File 'lib/engram/provenance.rb', line 35 def ==(other) other.is_a?(self.class) && to_h == other.to_h end |
#end_exclusive? ⇒ Boolean
33 |
# File 'lib/engram/provenance.rb', line 33 def end_exclusive? = true |
#hash ⇒ Object
40 |
# File 'lib/engram/provenance.rb', line 40 def hash = to_h.hash |
#to_h ⇒ Object
42 43 44 |
# File 'lib/engram/provenance.rb', line 42 def to_h {"start_offset" => start_offset, "end_offset" => end_offset, "offset_unit" => offset_unit} end |