Class: SimpleInlineTextAnnotation::Denotation

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_inline_text_annotation/denotation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(begin_pos, end_pos, obj, id = nil) ⇒ Denotation

Returns a new instance of Denotation.



10
11
12
13
14
15
# File 'lib/simple_inline_text_annotation/denotation.rb', line 10

def initialize(begin_pos, end_pos, obj, id = nil)
  @begin_pos = begin_pos
  @end_pos = end_pos
  @obj = obj
  @id = id
end

Instance Attribute Details

#begin_posObject (readonly)

Returns the value of attribute begin_pos.



8
9
10
# File 'lib/simple_inline_text_annotation/denotation.rb', line 8

def begin_pos
  @begin_pos
end

#end_posObject (readonly)

Returns the value of attribute end_pos.



8
9
10
# File 'lib/simple_inline_text_annotation/denotation.rb', line 8

def end_pos
  @end_pos
end

#idObject (readonly)

Returns the value of attribute id.



8
9
10
# File 'lib/simple_inline_text_annotation/denotation.rb', line 8

def id
  @id
end

#objObject (readonly)

Returns the value of attribute obj.



8
9
10
# File 'lib/simple_inline_text_annotation/denotation.rb', line 8

def obj
  @obj
end

Instance Method Details

#boundary_crossing?(other) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
48
49
50
# File 'lib/simple_inline_text_annotation/denotation.rb', line 45

def boundary_crossing?(other)
  starts_inside_other = @begin_pos > other.begin_pos && @begin_pos < other.end_pos
  ends_inside_other = @end_pos > other.begin_pos && @end_pos < other.end_pos

  starts_inside_other || ends_inside_other
end

#nested_within?(other) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/simple_inline_text_annotation/denotation.rb', line 25

def nested_within?(other)
  other.begin_pos <= @begin_pos && @end_pos <= other.end_pos
end

#out_of_bounds?(text_length) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/simple_inline_text_annotation/denotation.rb', line 41

def out_of_bounds?(text_length)
  @begin_pos >= text_length || @end_pos > text_length
end

#position_invalid?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/simple_inline_text_annotation/denotation.rb', line 37

def position_invalid?
  @begin_pos > @end_pos
end

#position_negative?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/simple_inline_text_annotation/denotation.rb', line 33

def position_negative?
  @begin_pos.negative? || @end_pos.negative?
end

#position_not_integer?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/simple_inline_text_annotation/denotation.rb', line 29

def position_not_integer?
  !(@begin_pos.is_a?(Integer) && @end_pos.is_a?(Integer))
end

#spanObject



17
18
19
# File 'lib/simple_inline_text_annotation/denotation.rb', line 17

def span
  { begin: @begin_pos, end: @end_pos }
end

#to_hObject



21
22
23
# File 'lib/simple_inline_text_annotation/denotation.rb', line 21

def to_h
  { id: @id, span: span, obj: @obj }.compact
end