Sha256: c8a2529969ad39df3e25745a1ec0f041e68c2d961ebe95ca1620a63081372358
Contents?: true
Size: 1 KB
Versions: 13
Compression:
Stored size: 1 KB
Contents
module RBS class Buffer attr_reader :name attr_reader :content attr_reader :lines attr_reader :ranges def initialize(name:, content:) @name = name @content = content @lines = content.lines @ranges = [] offset = 0 lines.each do |line| size = line.size range = offset...(offset+size) ranges << range offset += size end end def pos_to_loc(pos) index = ranges.bsearch_index do |range| pos < range.end ? true : false end if index [index + 1, pos - ranges[index].begin] else [ranges.size + 1, 0] end end def loc_to_pos(loc) line, column = loc if range = ranges[line - 1] range.begin + column else last_position end end def last_position content.size end def inspect "#<RBS::Buffer:#{__id__} @name=#{name}, @content=#{content.bytesize} bytes, @lines=#{lines.size} lines,>" end end end
Version data entries
13 entries across 13 versions & 1 rubygems