Class: Vedeu::Editor::Cropper

Inherits:
Object
  • Object
show all
Defined in:
lib/vedeu/editor/cropper.rb

Overview

Crop the lines to the visible area of the document, as defined by the geometry provided.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lines:, height:, width:, ox:, oy:) ⇒ Vedeu::Editor::Cropper

Returns a new instance of Vedeu::Editor::Cropper.

Parameters:



18
19
20
21
22
23
24
# File 'lib/vedeu/editor/cropper.rb', line 18

def initialize(lines:, height:, width:, ox:, oy:)
  @lines  = lines
  @height = height
  @width  = width
  @ox     = ox
  @oy     = oy
end

Instance Attribute Details

#heightFixnum (readonly, protected)

Returns:

  • (Fixnum)


40
41
42
# File 'lib/vedeu/editor/cropper.rb', line 40

def height
  @height
end

#oxFixnum (readonly, protected)

Returns:

  • (Fixnum)


48
49
50
# File 'lib/vedeu/editor/cropper.rb', line 48

def ox
  @ox
end

#oyFixnum (readonly, protected)

Returns:

  • (Fixnum)


52
53
54
# File 'lib/vedeu/editor/cropper.rb', line 52

def oy
  @oy
end

#widthFixnum (readonly, protected)

Returns:

  • (Fixnum)


44
45
46
# File 'lib/vedeu/editor/cropper.rb', line 44

def width
  @width
end

Instance Method Details

#columns(line) ⇒ String (private)

Return a range of visible characters from each line.

Returns:

  • (String)


66
67
68
# File 'lib/vedeu/editor/cropper.rb', line 66

def columns(line)
  line[ox...(ox + width)] || ''
end

#croppedArray<void>

Note:

If there are no lines of content, we return an empty

Returns the lines cropped.

array. If there are any empty lines, then they are discarded.

Returns:

  • (Array<void>)


32
33
34
# File 'lib/vedeu/editor/cropper.rb', line 32

def cropped
  lines.map { |line| columns(line) }
end

#linesVedeu::Editor::Lines (private)

Return a range of visible lines.



59
60
61
# File 'lib/vedeu/editor/cropper.rb', line 59

def lines
  @lines[oy...(oy + height)] || []
end