Class: Vedeu::Editor::Cropper Private
- Inherits:
-
Object
- Object
- Vedeu::Editor::Cropper
- Extended by:
- Forwardable
- Includes:
- Common
- Defined in:
- lib/vedeu/editor/cropper.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Crop the lines to the visible area of the document, as defined by the geometry provided.
Instance Attribute Summary collapse
-
#name ⇒ NilClass|Symbol|String
readonly
protected
private
The name of the model, the target model or the name of the associated model.
- #ox ⇒ Fixnum readonly protected private
- #oy ⇒ Fixnum readonly protected private
Instance Method Summary collapse
-
#geometry ⇒ Vedeu::Geometries::Geometry
private
private
Returns the named geometry from the geometries repository.
-
#initialize(lines:, ox:, oy:, name:) ⇒ Vedeu::Editor::Cropper
constructor
private
Returns a new instance of Vedeu::Editor::Cropper.
-
#lines ⇒ Vedeu::Editor::Lines
private
private
Return a range of visible lines.
- #to_a ⇒ Array<void> private
-
#viewport ⇒ Array<void>
private
Returns the visible lines as a sequence of Cells::Char objects.
-
#visible ⇒ Array<void>
private
private
Returns the visible lines and their respective content, determined by the offsets ‘ox’ and ‘oy’.
Methods included from Common
#absent?, #array?, #boolean, #boolean?, #empty_value?, #escape?, #falsy?, #hash?, #line_model?, #numeric?, #positionable?, #present?, #snake_case, #stream_model?, #string?, #symbol?, #truthy?, #view_model?
Constructor Details
#initialize(lines:, ox:, oy:, name:) ⇒ Vedeu::Editor::Cropper
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Vedeu::Editor::Cropper.
32 33 34 35 36 37 |
# File 'lib/vedeu/editor/cropper.rb', line 32 def initialize(lines:, ox:, oy:, name:) @lines = lines @name = present?(name) ? name : Vedeu.focus @ox = ox @oy = oy end |
Instance Attribute Details
#name ⇒ NilClass|Symbol|String (readonly, protected)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The name of the model, the target model or the name of the associated model.
68 69 70 |
# File 'lib/vedeu/editor/cropper.rb', line 68 def name @name end |
#ox ⇒ Fixnum (readonly, protected)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
72 73 74 |
# File 'lib/vedeu/editor/cropper.rb', line 72 def ox @ox end |
#oy ⇒ Fixnum (readonly, protected)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
76 77 78 |
# File 'lib/vedeu/editor/cropper.rb', line 76 def oy @oy end |
Instance Method Details
#geometry ⇒ Vedeu::Geometries::Geometry (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the named geometry from the geometries repository.
99 100 101 |
# File 'lib/vedeu/editor/cropper.rb', line 99 def geometry @_geometry ||= Vedeu.geometries.by_name(name) end |
#lines ⇒ Vedeu::Editor::Lines (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return a range of visible lines.
94 95 96 |
# File 'lib/vedeu/editor/cropper.rb', line 94 def lines @lines[oy...(oy + bordered_height)] || [] end |
#to_a ⇒ Array<void>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
60 61 62 |
# File 'lib/vedeu/editor/cropper.rb', line 60 def to_a visible end |
#viewport ⇒ Array<void>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the visible lines as a sequence of Cells::Char objects.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/vedeu/editor/cropper.rb', line 43 def out = [] visible.each_with_index do |line, iy| line.chars.each_with_index do |char, ix| out << Vedeu::Cells::Char.new( name: name, position: Vedeu::Geometries::Position.new((by + iy), (bx + ix)), value: char ) end end out end |
#visible ⇒ Array<void> (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
If there are no lines of content, we return an empty
Returns the visible lines and their respective content, determined by the offsets ‘ox’ and ‘oy’.
array. If there are any empty lines, then they are discarded.
87 88 89 |
# File 'lib/vedeu/editor/cropper.rb', line 87 def visible lines.map { |line| line[ox...(ox + bordered_width)] || '' } end |