Class: Pry::CInternals::ETagParser::CFile

Inherits:
Object
  • Object
show all
Defined in:
lib/pry-doc/pry_ext/show_source_with_c_internals/c_file.rb

Constant Summary collapse

SYMBOL_SEPARATOR =

Used to separate symbol from line number

"\x7f"
ALTERNATIVE_SEPARATOR =
"\x1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_name: nil, content: nil, ruby_source_folder: nil) ⇒ CFile

Returns a new instance of CFile.



20
21
22
23
24
# File 'lib/pry-doc/pry_ext/show_source_with_c_internals/c_file.rb', line 20

def initialize(file_name: nil, content: nil, ruby_source_folder: nil)
  @ruby_source_folder = ruby_source_folder
  @content = content
  @file_name = file_name
end

Instance Attribute Details

#file_nameObject

Returns the value of attribute file_name.



17
18
19
# File 'lib/pry-doc/pry_ext/show_source_with_c_internals/c_file.rb', line 17

def file_name
  @file_name
end

#ruby_source_folderObject (readonly)

Returns the value of attribute ruby_source_folder.



18
19
20
# File 'lib/pry-doc/pry_ext/show_source_with_c_internals/c_file.rb', line 18

def ruby_source_folder
  @ruby_source_folder
end

Instance Method Details

#symbol_mapObject

Convert a C file to a map of symbols => SourceLocation that are found in that file e.g { "foo" => [SourceLocation], "bar" => [SourceLocation] }



29
30
31
32
33
34
35
36
37
# File 'lib/pry-doc/pry_ext/show_source_with_c_internals/c_file.rb', line 29

def symbol_map
  return @symbol_map if @symbol_map
  @symbol_map = @content.each_with_object({}) do |v, h|
    sep = v.include?(ALTERNATIVE_SEPARATOR) ? ALTERNATIVE_SEPARATOR : SYMBOL_SEPARATOR
    symbol, line_number = v.split(sep)
    next if symbol.strip =~ /^\w+$/ # these symbols are usually errors in etags
    h[cleanup_symbol(symbol)] = [source_location_for(symbol, line_number)]
  end
end