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

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:



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

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


64
65
66
# File 'lib/vedeu/editor/cropper.rb', line 64

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)


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

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)


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.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

  • (Boolean)

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

Returns:

  • (String)


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.

Examples:

demodulize('Vedeu::SomeModule::SomeClass') # => "SomeClass"

Parameters:

  • klass (Class|String)

Returns:

  • (String)

#interfaceObject (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

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



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.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

  • (Boolean)

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

Examples:

snake_case(MyClassName) # => "my_class_name"
snake_case(NameSpaced::ClassName)
# => "name_spaced/class_name"

Parameters:

  • name (String)

Returns:

  • (String)

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


56
57
58
# File 'lib/vedeu/editor/cropper.rb', line 56

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 View::Char objects.

Returns:

  • (Array<void>)


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

def viewport
  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

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


82
83
84
# File 'lib/vedeu/editor/cropper.rb', line 82

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