Class: JarEd::Buffer

Inherits:
Object
  • Object
show all
Defined in:
lib/jared/buffer.rb

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Buffer

Returns a new instance of Buffer.



5
6
7
# File 'lib/jared/buffer.rb', line 5

def initialize(filename)
  @file = File.open(filename, "r")
end

Instance Method Details

#linesObject



9
10
11
# File 'lib/jared/buffer.rb', line 9

def lines
  @lines ||= file.each_line.to_a.map { |line| BufferLine.new(line) }
end

#wrapped_lines(width:, height:, offset:) ⇒ Object



13
14
15
16
17
18
# File 'lib/jared/buffer.rb', line 13

def wrapped_lines(width:, height:, offset:)
  lines.
    slice(offset, lines.length - 1).
    flat_map { |line| line.wrap(width: width) }.
    first(height)
end