class Laplus::Source
Constants
- SnipTooManyLines
Attributes
parser[R]
path[R]
reader[R]
Public Class Methods
new(path, reader = File, parser = Parser.new)
click to toggle source
# File lib/laplus/source.rb, line 9 def initialize(path, reader = File, parser = Parser.new) @path = path @reader = reader @parser = parser end
Public Instance Methods
snip_code_at(line)
click to toggle source
# 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
Private Instance Methods
lines()
click to toggle source
# File lib/laplus/source.rb, line 29 def lines @lines ||= reader.readlines(path) end
snip_line_in(range)
click to toggle source
# File lib/laplus/source.rb, line 33 def snip_line_in(range) lines[range].join end