Module: ActiveMutator::SourceLocation
- Defined in:
- lib/active_mutator/source_location.rb
Overview
1-based line/column (never 0 — the Stryker schema rejects 0) for an exclusive byte range within a source string.
Class Method Summary collapse
Class Method Details
.locate(source, byte_range) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/active_mutator/source_location.rb', line 5 def self.locate(source, byte_range) { start: position(source, byte_range.begin), end: position(source, byte_range.end) } end |
.position(source, offset) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/active_mutator/source_location.rb', line 12 def self.position(source, offset) prefix = source.byteslice(0, offset) last_newline = prefix.rindex("\n") { line: prefix.count("\n") + 1, column: offset - (last_newline ? last_newline + 1 : 0) + 1 } end |