Class: Vedeu::Editor::Cropper
- Inherits:
-
Object
- Object
- Vedeu::Editor::Cropper
- Extended by:
- Forwardable
- Includes:
- Common
- 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
- #name ⇒ String|Symbol readonly protected
- #ox ⇒ Fixnum readonly protected
- #oy ⇒ Fixnum readonly protected
Instance Method Summary collapse
-
#absent?(variable) ⇒ Boolean
included
from Common
Returns a boolean indicating whether a variable is nil or empty.
- #border ⇒ Vedeu::Borders::Border private
-
#columns(line) ⇒ String
private
Return a range of visible characters from each line.
-
#demodulize(klass) ⇒ String
included
from Common
Removes the module part from the expression in the string.
-
#initialize(lines:, ox:, oy:, name:) ⇒ Vedeu::Editor::Cropper
constructor
Returns a new instance of Vedeu::Editor::Cropper.
- #interface ⇒ Vedeu::Interfaces::Interface private
-
#lines ⇒ Vedeu::Editor::Lines
private
Return a range of visible lines.
-
#present?(variable) ⇒ Boolean
included
from Common
Returns a boolean indicating whether a variable has a useful value.
-
#snake_case(name) ⇒ String
included
from Common
Converts a class name to a lowercase snake case string.
- #to_a ⇒ Array<void>
-
#viewport ⇒ Array<void>
Returns the visible lines as a sequence of View::Char objects.
-
#visible ⇒ Array<void>
private
Returns the visible lines.
Constructor Details
#initialize(lines:, ox:, oy:, name:) ⇒ Vedeu::Editor::Cropper
Returns a new instance of Vedeu::Editor::Cropper.
28 29 30 31 32 33 |
# File 'lib/vedeu/editor/cropper.rb', line 28 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)
62 63 64 |
# File 'lib/vedeu/editor/cropper.rb', line 62 def name @name end |
#ox ⇒ Fixnum (readonly, protected)
66 67 68 |
# File 'lib/vedeu/editor/cropper.rb', line 66 def ox @ox end |
#oy ⇒ Fixnum (readonly, protected)
70 71 72 |
# File 'lib/vedeu/editor/cropper.rb', line 70 def oy @oy end |
Instance Method Details
#absent?(variable) ⇒ Boolean Originally defined in module Common
Returns a boolean indicating whether a variable is nil or empty.
#border ⇒ Vedeu::Borders::Border (private)
104 105 106 |
# File 'lib/vedeu/editor/cropper.rb', line 104 def border @border ||= Vedeu.borders.by_name(name) end |
#columns(line) ⇒ String (private)
Return a range of visible characters from each line.
99 100 101 |
# File 'lib/vedeu/editor/cropper.rb', line 99 def columns(line) line[ox...(ox + width)] || '' end |
#demodulize(klass) ⇒ String Originally defined in module Common
Removes the module part from the expression in the string.
#interface ⇒ Vedeu::Interfaces::Interface (private)
92 93 94 |
# File 'lib/vedeu/editor/cropper.rb', line 92 def interface @interface ||= Vedeu.interfaces.by_name(name) end |
#lines ⇒ Vedeu::Editor::Lines (private)
Return a range of visible lines.
87 88 89 |
# File 'lib/vedeu/editor/cropper.rb', line 87 def lines @lines[oy...(oy + height)] || [] end |
#present?(variable) ⇒ Boolean Originally defined in module Common
Returns a boolean indicating whether a variable has a useful value.
#snake_case(name) ⇒ String Originally defined in module Common
Converts a class name to a lowercase snake case string.
#to_a ⇒ Array<void>
54 55 56 |
# File 'lib/vedeu/editor/cropper.rb', line 54 def to_a visible end |
#viewport ⇒ Array<void>
Returns the visible lines as a sequence of View::Char objects.
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/vedeu/editor/cropper.rb', line 39 def out = [] visible.each_with_index do |line, iy| line.chars.each_with_index do |char, ix| out << Vedeu::Views::Char.new(parent: interface, position: [(by + iy), (bx + ix)], value: char.freeze) end end out end |
#visible ⇒ Array<void> (private)
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.
80 81 82 |
# File 'lib/vedeu/editor/cropper.rb', line 80 def visible lines.map { |line| columns(line) } end |