Class: CodeKeeper::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/code_keeper/parser.rb

Overview

Search and parse ruby file

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ Parser

Returns a new instance of Parser.



8
9
10
11
12
13
# File 'lib/code_keeper/parser.rb', line 8

def initialize(file_path)
  source = File.read(File.expand_path(file_path))
  @processed_source = ::RuboCop::AST::ProcessedSource.new(source, RUBY_VERSION.to_f)
rescue Errno::ENOENT
  raise TargetFileNotFoundError, "The target file does not exist. Check the file path: #{file_path}."
end

Instance Attribute Details

#processed_sourceObject (readonly)

Returns the value of attribute processed_source.



6
7
8
# File 'lib/code_keeper/parser.rb', line 6

def processed_source
  @processed_source
end

Class Method Details

.parse(file_path) ⇒ Object



16
17
18
19
# File 'lib/code_keeper/parser.rb', line 16

def parse(file_path)
  parser = new(file_path)
  parser.processed_source
end