Class: Vedeu::Editor::Cropper
- Inherits:
-
Object
- Object
- Vedeu::Editor::Cropper
- 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
- #height ⇒ Fixnum readonly protected
- #ox ⇒ Fixnum readonly protected
- #oy ⇒ Fixnum readonly protected
- #width ⇒ Fixnum readonly protected
Instance Method Summary collapse
-
#columns(line) ⇒ String
private
Return a range of visible characters from each line.
-
#cropped ⇒ Array<void>
Returns the lines cropped.
-
#initialize(lines:, height:, width:, ox:, oy:) ⇒ Vedeu::Editor::Cropper
constructor
Returns a new instance of Vedeu::Editor::Cropper.
-
#lines ⇒ Vedeu::Editor::Lines
private
Return a range of visible lines.
Constructor Details
#initialize(lines:, height:, width:, ox:, oy:) ⇒ Vedeu::Editor::Cropper
Returns a new instance of Vedeu::Editor::Cropper.
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
#height ⇒ Fixnum (readonly, protected)
40 41 42 |
# File 'lib/vedeu/editor/cropper.rb', line 40 def height @height end |
#ox ⇒ Fixnum (readonly, protected)
48 49 50 |
# File 'lib/vedeu/editor/cropper.rb', line 48 def ox @ox end |
#oy ⇒ Fixnum (readonly, protected)
52 53 54 |
# File 'lib/vedeu/editor/cropper.rb', line 52 def oy @oy end |
#width ⇒ Fixnum (readonly, protected)
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.
66 67 68 |
# File 'lib/vedeu/editor/cropper.rb', line 66 def columns(line) line[ox...(ox + width)] || '' end |
#cropped ⇒ Array<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.
32 33 34 |
# File 'lib/vedeu/editor/cropper.rb', line 32 def cropped lines.map { |line| columns(line) } end |
#lines ⇒ Vedeu::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 |