Class: Paco::Index
- Inherits:
-
Struct
- Object
- Struct
- Paco::Index
- Defined in:
- lib/paco/index.rb
Instance Attribute Summary collapse
-
#column ⇒ Object
Returns the value of attribute column.
-
#line ⇒ Object
Returns the value of attribute line.
-
#pos ⇒ Object
Returns the value of attribute pos.
Class Method Summary collapse
Instance Attribute Details
#column ⇒ Object
Returns the value of attribute column
2 3 4 |
# File 'lib/paco/index.rb', line 2 def column @column end |
#line ⇒ Object
Returns the value of attribute line
2 3 4 |
# File 'lib/paco/index.rb', line 2 def line @line end |
#pos ⇒ Object
Returns the value of attribute pos
2 3 4 |
# File 'lib/paco/index.rb', line 2 def pos @pos end |
Class Method Details
.calculate(input:, pos:) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/paco/index.rb', line 5 def self.calculate(input:, pos:) raise ArgumentError, "`pos` must be a non-negative integer" if pos < 0 raise ArgumentError, "`pos` is grater then input length" if pos > input.length lines = input[0..pos].lines line = lines.empty? ? 1 : lines.length column = lines.last&.length || 1 new(pos, line, column) end |