Class: Escort::Formatter::CursorPosition
- Inherits:
-
Object
- Object
- Escort::Formatter::CursorPosition
- Defined in:
- lib/escort/formatter/cursor_position.rb
Instance Attribute Summary collapse
-
#max_line_width ⇒ Object
readonly
Returns the value of attribute max_line_width.
-
#position ⇒ Object
readonly
Returns the value of attribute position.
Instance Method Summary collapse
- #chars_to_end_of_line ⇒ Object
-
#initialize(max_line_width) ⇒ CursorPosition
constructor
A new instance of CursorPosition.
- #newline? ⇒ Boolean
- #reset ⇒ Object
- #update_for(string) ⇒ Object
Constructor Details
#initialize(max_line_width) ⇒ CursorPosition
Returns a new instance of CursorPosition.
6 7 8 9 |
# File 'lib/escort/formatter/cursor_position.rb', line 6 def initialize(max_line_width) @max_line_width = max_line_width reset end |
Instance Attribute Details
#max_line_width ⇒ Object (readonly)
Returns the value of attribute max_line_width.
4 5 6 |
# File 'lib/escort/formatter/cursor_position.rb', line 4 def max_line_width @max_line_width end |
#position ⇒ Object (readonly)
Returns the value of attribute position.
4 5 6 |
# File 'lib/escort/formatter/cursor_position.rb', line 4 def position @position end |
Instance Method Details
#chars_to_end_of_line ⇒ Object
24 25 26 |
# File 'lib/escort/formatter/cursor_position.rb', line 24 def chars_to_end_of_line max_line_width - position end |
#newline? ⇒ Boolean
16 17 18 |
# File 'lib/escort/formatter/cursor_position.rb', line 16 def newline? @position == 0 end |
#reset ⇒ Object
20 21 22 |
# File 'lib/escort/formatter/cursor_position.rb', line 20 def reset @position = 0 end |
#update_for(string) ⇒ Object
11 12 13 14 |
# File 'lib/escort/formatter/cursor_position.rb', line 11 def update_for(string) @position += string.length raise Escort::InternalError.new("Cursor position for help output is out of bounds") if position > max_line_width end |