Class: Pry::CInternals::ETagParser::CFile
- Inherits:
-
Object
- Object
- Pry::CInternals::ETagParser::CFile
- 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
-
#file_name ⇒ Object
Returns the value of attribute file_name.
-
#ruby_source_folder ⇒ Object
readonly
Returns the value of attribute ruby_source_folder.
Instance Method Summary collapse
-
#initialize(file_name: nil, content: nil, ruby_source_folder: nil) ⇒ CFile
constructor
A new instance of CFile.
-
#symbol_map ⇒ Object
Convert a C file to a map of symbols => SourceLocation that are found in that file e.g { "foo" => [SourceLocation], "bar" => [SourceLocation] }.
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_name ⇒ Object
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_folder ⇒ Object (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_map ⇒ Object
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 |