Class: Laplus::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/laplus/source.rb

Constant Summary collapse

SnipTooManyLines =
Class.new(Laplus::Error)

Instance Method Summary collapse

Constructor Details

#initialize(path, reader = File, parser = Parser.new) ⇒ Source

Returns a new instance of Source.



9
10
11
12
13
# File 'lib/laplus/source.rb', line 9

def initialize(path, reader = File, parser = Parser.new)
  @path = path
  @reader = reader
  @parser = parser
end

Instance Method Details

#snip_code_at(line) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/laplus/source.rb', line 15

def snip_code_at(line)
  beginning_index = line - 1
  ending_index = (beginning_index..).find do |index|
    raise SnipTooManyLines if index - beginning_index > 100
    code = lines[beginning_index..index].join
    parser.parse(code)
  end
  snip_line_in(beginning_index..ending_index)
end