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:



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)


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

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)


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

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)


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

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:

#become(klass, attributes) ⇒ Class 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 one class into another.

Parameters:

  • klass (Class)

    The class to become an instance of.

  • attributes (Hash)

    The attributes of klass.

Returns:

  • (Class)

    Returns a new instance of klass.

#boolean(value) ⇒ 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 the value was a boolean.

Parameters:

  • value (void)

Returns:

#boolean?(value) ⇒ 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 the value is a Boolean.

Parameters:

Returns:

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


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

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

#escape?(value) ⇒ 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 the value is an escape sequence object (e.g. Vedeu::Cells::Escape.)

Returns:

#falsy?(value) ⇒ 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 the value should be considered false.

Parameters:

  • value (void)

Returns:

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



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

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

#hash?(value) ⇒ 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 the value is a Hash.

Parameters:

  • value (Hash|void)

Returns:

#line_model?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 the model is a Views::Line.

Returns:

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



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

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

#numeric?(value) ⇒ 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 the value is a Fixnum.

Parameters:

  • value (Fixnum|void)

Returns:

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

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

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"

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

Parameters:

  • klass (Module|Class|String)

Returns:

  • (String)

#stream_model?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 the model is a Views::Stream.

Returns:

#string?(value) ⇒ 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 the value is a Fixnum.

Parameters:

  • value (String|void)

Returns:

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


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

def to_a
  visible
end

#truthy?(value) ⇒ 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 the value should be considered true.

Parameters:

  • value (void)

Returns:

#view_model?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 the model is a Views::View.

Returns:

#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
# 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|
      out << Vedeu::Cells::Char.new(name:     name,
                                    position: [(by + iy), (bx + ix)],
                                    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>)


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

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