123456789_123456789_123456789_123456789_123456789_

Class: Prism::Relocation::CodeUnitColumnsField

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

Overview

A field representing the start and end code unit columns for a specific encoding.

Class Method Summary

Instance Attribute Summary

  • #encoding readonly

    The associated encoding for the code units.

  • #repository readonly

    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 column of a value for a particular encoding.

  • #cache private

    Lazily create a code units cache for the associated encoding.

Constructor Details

.new(repository, encoding) ⇒ CodeUnitColumnsField

Initialize a new field with the associated repository and encoding.

[ GitHub ]

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

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 287

attr_reader :encoding

#repository (readonly)

The repository object that is used for lazily creating a code units cache.

[ GitHub ]

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

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 308

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

#fields(value)

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

[ GitHub ]

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

def fields(value)
  {
    start_code_units_column: value.cached_start_code_units_column(cache),
    end_code_units_column: value.cached_end_code_units_column(cache)
  }
end