123456789_123456789_123456789_123456789_123456789_

Class: Prism::Relocation::CodeUnitOffsetsField

Relationships & Source Files
Inherits: Object
Defined in: lib/prism/relocation.rb

Overview

A field representing the start and end code unit offsets.

Class Method Summary

Instance Attribute Summary

  • #encoding readonly

    The associated encoding for the code units.

  • #repository readonly

    A pointer to the repository object that is used for lazily creating a code units cache.

Instance Method Summary

  • #fields(value)

    Fetches the start and end code units offset of a value for a particular encoding.

  • #cache private

    Lazily create a code units cache for the associated encoding.

Constructor Details

.new(repository, encoding) ⇒ CodeUnitOffsetsField

Initialize a new field with the associated repository and encoding.

[ GitHub ]

  
# File 'lib/prism/relocation.rb', line 237

def initialize(repository, encoding)
  @repository = repository
  @encoding = encoding
  @cache = nil
end

Instance Attribute Details

#encoding (readonly)

The associated encoding for the code units.

[ GitHub ]

  
# File 'lib/prism/relocation.rb', line 234

attr_reader :encoding

#repository (readonly)

A pointer to the repository object that is used for lazily creating a code units cache.

[ GitHub ]

  
# File 'lib/prism/relocation.rb', line 231

attr_reader :repository

Instance Method Details

#cache (private)

Lazily create a code units cache for the associated encoding.

[ GitHub ]

  
# File 'lib/prism/relocation.rb', line 255

def cache
  @cache ||= repository.code_units_cache(encoding)
end

#fields(value)

Fetches the start and end code units offset of a value for a particular encoding.

[ GitHub ]

  
# File 'lib/prism/relocation.rb', line 245

def fields(value)
  {
    start_code_units_offset: value.cached_start_code_units_offset(cache),
    end_code_units_offset: value.cached_end_code_units_offset(cache)
  }
end