Class: PryCoolline::ParenMatch::Pair

Inherits:
Struct
  • Object
show all
Defined in:
lib/pry-coolline/paren_match.rb

Overview

Represents a pair that should be matched.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#closeCloseToken?

Returns the current value of close.

Returns:

  • (CloseToken, nil)

    the current value of close



34
35
36
# File 'lib/pry-coolline/paren_match.rb', line 34

def close
  @close
end

#openOpenToken?

Returns the current value of open.

Returns:

  • (OpenToken, nil)

    the current value of open



34
35
36
# File 'lib/pry-coolline/paren_match.rb', line 34

def open
  @open
end

Instance Method Details

#correctly_matched?(pairs = Pairs) ⇒ Boolean

Returns True if the opening character and the closing characters are both present and match correctly.

Returns:

  • (Boolean)

    True if the opening character and the closing characters are both present and match correctly.



37
38
39
# File 'lib/pry-coolline/paren_match.rb', line 37

def correctly_matched?(pairs = Pairs)
  open and close and pairs[open.str] == close.str
end

#insertion_positionsArray<Array<Integer>>

Returns Positions where the user can insert color indicators, in descending order so that String#insert can be used safely.

Examples:

insertion_positions.each do |before, after|
  string.insert after, clear_code
  string.insert before, background_code
end

Returns:

  • (Array<Array<Integer>>)

    Positions where the user can insert color indicators, in descending order so that String#insert can be used safely.



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/pry-coolline/paren_match.rb', line 50

def insertion_positions
  ary = []

  if close
    ary << [close.code_pos, close.code_pos + close.str.size]
  end

  if open
    ary << [open.code_pos, open.code_pos + open.str.size]
  end

  ary
end