Class: RLSL::Prism::SourceExtractor::BlockLocator

Inherits:
Object
  • Object
show all
Defined in:
lib/rlsl/prism/source_extractor/block_locator.rb

Instance Method Summary collapse

Instance Method Details

#extract(source, start_line) ⇒ Object



7
8
9
# File 'lib/rlsl/prism/source_extractor/block_locator.rb', line 7

def extract(source, start_line)
  extract_unit(source, start_line).to_source
end

#extract_unit(source, start_line) ⇒ Object

Raises:



11
12
13
14
15
16
17
18
19
# File 'lib/rlsl/prism/source_extractor/block_locator.rb', line 11

def extract_unit(source, start_line)
  parsed = ::Prism.parse(source)
  raise SourceNotAvailable, "Unable to parse block source" unless parsed.success?

  block = block_at_line(parsed.value, start_line)
  raise SourceNotAvailable, "Unable to locate block source" unless block

  SourceUnit.from_block(block)
end