Class: TextWeaver::InsertPosition

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/text_weaver/insert_position.rb

Overview

BodyPositions allow one to point to a position in a Logi, and insert some text there.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(position, set, text) ⇒ InsertPosition

Initializes a new InsertPosition.



13
14
15
16
17
18
19
20
21
# File 'lib/text_weaver/insert_position.rb', line 13

def initialize(position, set, text)
  if position < 0
    raise TextWeaver::Error.new(position, set), 'Tried to create a negative InsertPosition'
  end

  self.position = position
  self.set = set
  self.text = text
end

Instance Attribute Details

#positionObject

Returns the value of attribute position.



7
8
9
# File 'lib/text_weaver/insert_position.rb', line 7

def position
  @position
end

#setObject

Returns the value of attribute set.



7
8
9
# File 'lib/text_weaver/insert_position.rb', line 7

def set
  @set
end

#textObject

Returns the value of attribute text.



7
8
9
# File 'lib/text_weaver/insert_position.rb', line 7

def text
  @text
end

Instance Method Details

#<=>(other) ⇒ Object

First the positions are compared.

1 > 4 => true
2 > 3 => true

If those are equal the sets are compared.

-2 < -1

If the sets are also equal, an exception is thrown.

Sets are used for keeping links apart from comments, etc… Both links and comments etc. should be clustered and parsed from templates as clusters.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/text_weaver/insert_position.rb', line 42

def <=>(other)
  if self.position < other.position
    return -1
  elsif self.position > other.position
    return 1
  else
    if self.set < other.set
      return -1
    elsif self.set > other.set
      return 1
    else
      raise TextWeaver::Error.new(position, set), 'Overlap between same set of BodyPositions'
    end
  end
end