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 ⇒ String|Symbol readonly protected private
- #ox ⇒ Fixnum readonly protected private
- #oy ⇒ Fixnum readonly protected private
Instance Method Summary collapse
-
#absent?(variable) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether a variable is nil or empty.
-
#border ⇒ Object
private
private
Returns the border for the interface.
-
#columns(line) ⇒ String
private
private
Return a range of visible characters from each line.
-
#demodulize(klass) ⇒ String
included
from Common
private
Removes the module part from the expression in the string.
-
#initialize(lines:, ox:, oy:, name:) ⇒ Vedeu::Editor::Cropper
constructor
private
Returns a new instance of Vedeu::Editor::Cropper.
-
#interface ⇒ Object
private
private
Returns the interface by name.
-
#lines ⇒ Vedeu::Editor::Lines
private
private
Return a range of visible lines.
-
#present?(variable) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether a variable has a useful value.
-
#snake_case(name) ⇒ String
included
from Common
private
Converts a class name to a lowercase snake case string.
- #to_a ⇒ Array<void> private
-
#viewport ⇒ Array<void>
private
Returns the visible lines as a sequence of View::Char objects.
-
#visible ⇒ Array<void>
private
private
Returns the visible lines.
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.
30 31 32 33 34 35 |
# File 'lib/vedeu/editor/cropper.rb', line 30 def initialize(lines:, ox:, oy:, name:) @lines = lines @name = present?(name) ? name : Vedeu.focus @ox = ox @oy = oy end |
Instance Attribute Details
#name ⇒ String|Symbol (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.
64 65 66 |
# File 'lib/vedeu/editor/cropper.rb', line 64 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.
68 69 70 |
# File 'lib/vedeu/editor/cropper.rb', line 68 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.
72 73 74 |
# File 'lib/vedeu/editor/cropper.rb', line 72 def oy @oy end |
Instance Method Details
#absent?(variable) ⇒ Boolean Originally defined in module Common
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 boolean indicating whether a variable is nil or empty.
#border ⇒ Object (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 border for the interface.
110 111 112 |
# File 'lib/vedeu/editor/cropper.rb', line 110 def border @border ||= Vedeu.borders.by_name(name) end |
#columns(line) ⇒ String (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 characters from each line.
103 104 105 |
# File 'lib/vedeu/editor/cropper.rb', line 103 def columns(line) line[ox...(ox + width)] || '' end |
#demodulize(klass) ⇒ String Originally defined in module Common
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.
Removes the module part from the expression in the string.
#interface ⇒ Object (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 interface by name.
96 97 98 |
# File 'lib/vedeu/editor/cropper.rb', line 96 def interface @interface ||= Vedeu.interfaces.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.
89 90 91 |
# File 'lib/vedeu/editor/cropper.rb', line 89 def lines @lines[oy...(oy + height)] || [] end |
#present?(variable) ⇒ Boolean Originally defined in module Common
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 boolean indicating whether a variable has a useful value.
#snake_case(name) ⇒ String Originally defined in module Common
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.
Converts a class name to a lowercase snake case string.
#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.
56 57 58 |
# File 'lib/vedeu/editor/cropper.rb', line 56 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 View::Char objects.
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/vedeu/editor/cropper.rb', line 41 def out = [] visible.each_with_index do |line, iy| line.chars.each_with_index do |char, ix| out << Vedeu::Views::Char.new(name: name, position: [(by + iy), (bx + ix)], value: char.freeze) 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.
array. If there are any empty lines, then they are discarded.
82 83 84 |
# File 'lib/vedeu/editor/cropper.rb', line 82 def visible lines.map { |line| columns(line) } end |