Class: Vedeu::Editor::Cropper Private

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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.

Parameters:

  • lines (Vedeu::Editor::Lines)
  • name (NilClass|Symbol|String)

    The name of the model or target model to act upon. May default to ‘Vedeu.focus`.

  • ox (Fixnum)
  • oy (Fixnum)


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

#nameString|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.

Returns:

  • (String|Symbol)


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

def name
  @name
end

#oxFixnum (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:

  • (Fixnum)


71
72
73
# File 'lib/vedeu/editor/cropper.rb', line 71

def ox
  @ox
end

#oyFixnum (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:

  • (Fixnum)


75
76
77
# File 'lib/vedeu/editor/cropper.rb', line 75

def oy
  @oy
end

Instance Method Details

#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.

Returns:

  • (String)


99
100
101
# File 'lib/vedeu/editor/cropper.rb', line 99

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

#geometryObject (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.



106
107
108
# File 'lib/vedeu/editor/cropper.rb', line 106

def geometry
  @geometry ||= Vedeu.geometries.by_name(name)
end

#linesVedeu::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.



92
93
94
# File 'lib/vedeu/editor/cropper.rb', line 92

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

#to_aArray<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:

  • (Array<void>)


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

def to_a
  visible
end

#viewportArray<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.

Returns:

  • (Array<void>)


43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/vedeu/editor/cropper.rb', line 43

def viewport
  out = []

  visible.each_with_index do |line, iy|
    line.chars.each_with_index do |char, ix|
      position = Vedeu::Geometries::Position.new((by + iy), (bx + ix))
      out << Vedeu::Cells::Char.new(name:     name,
                                    position: position,
                                    value:    char)
    end
  end

  out
end

#visibleArray<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.

Note:

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.

Returns:

  • (Array<void>)


85
86
87
# File 'lib/vedeu/editor/cropper.rb', line 85

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