Class: Vedeu::Cursors::Coordinate Private

Inherits:
Object
  • Object
show all
Defined in:
lib/vedeu/cursors/coordinate.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.

Crudely corrects out of range values.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Vedeu::Cursors::Coordinate

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 new instance of Vedeu::Cursors::Coordinate.

Parameters:

  • attributes (Hash<Symbol => Fixnum|String|Symbol>) (defaults to: {})

Options Hash (attributes):

  • name (String|Symbol)
  • type (Symbol)
  • offset (Fixnum)


20
21
22
23
24
# File 'lib/vedeu/cursors/coordinate.rb', line 20

def initialize(attributes = {})
  defaults.merge!(attributes).each do |key, value|
    instance_variable_set("@#{key}", value)
  end
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)


73
74
75
# File 'lib/vedeu/cursors/coordinate.rb', line 73

def name
  @name
end

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


77
78
79
# File 'lib/vedeu/cursors/coordinate.rb', line 77

def offset
  @offset
end

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

  • (Symbol)


81
82
83
# File 'lib/vedeu/cursors/coordinate.rb', line 81

def type
  @type
end

Instance Method Details

#bdFixnum (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 the :bx or :by value from the geometry.

Returns:

  • (Fixnum)


102
103
104
# File 'lib/vedeu/cursors/coordinate.rb', line 102

def bd
  geometry.send(coordinate_type[1])
end

#bdnFixnum (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 the :bxn or :byn value from the geometry.

Returns:

  • (Fixnum)


109
110
111
# File 'lib/vedeu/cursors/coordinate.rb', line 109

def bdn
  geometry.send(coordinate_type[2])
end

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

Ascertain the correct methods to use for determining the coordinates.

Returns:

  • (Fixnum)

Raises:

  • (Vedeu::Error::InvalidSyntax)

    When the value given for an argument or parameter cannot be used because it is not valid for the use case, unsupported or the method expects a different type.



125
126
127
128
129
130
131
132
133
# File 'lib/vedeu/cursors/coordinate.rb', line 125

def coordinate_type
  @_type ||= case type
             when :x then [:x, :bx, :bxn, :bordered_width]
             when :y then [:y, :by, :byn, :bordered_height]
             else
               fail Vedeu::Error::InvalidSyntax,
                    'Coordinate type not given, cannot continue.'
             end
end

#dFixnum (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 the :x or :y value from the geometry.

Returns:

  • (Fixnum)


95
96
97
# File 'lib/vedeu/cursors/coordinate.rb', line 95

def d
  geometry.send(coordinate_type[0])
end

#d_dnFixnum (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 the :width or :height value from the geometry.

Returns:

  • (Fixnum)


116
117
118
# File 'lib/vedeu/cursors/coordinate.rb', line 116

def d_dn
  geometry.send(coordinate_type[3])
end

#d_positionFixnum Also known as: x, y

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 coordinate for a given index.

Examples:

# d_range = [4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
position     # => 4
position(-2) # => 4
position(2)  # => 6
position(15) # => 13

Returns:

  • (Fixnum)


52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/vedeu/cursors/coordinate.rb', line 52

def d_position
  pos = if offset <= 0
          d

        elsif offset > dn_index
          dn_position

        else
          d_range[offset]

        end

  Vedeu::Point.coerce(value: pos, min: bd, max: bdn).value
end

#d_rangeArray (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 an array with all coordinates from d to dn.

Examples:

# d_dn = 10
# d = 4
# dn = 14
d_range # => [4, 5, 6, 7, 8, 9, 10, 11, 12, 13]

Returns:

  • (Array)


157
158
159
# File 'lib/vedeu/cursors/coordinate.rb', line 157

def d_range
  (d...dn_position).to_a
end

#defaultsHash<Symbol => Fixnum|String|Symbol> (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.

The default values for a new instance of this class.

Returns:

  • (Hash<Symbol => Fixnum|String|Symbol>)


164
165
166
167
168
169
170
# File 'lib/vedeu/cursors/coordinate.rb', line 164

def defaults
  {
    name:   '',
    offset: nil,
    type:   :x,
  }
end

#dn_indexFixnum (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 maximum index for an area.

Examples:

# d_dn = 3
dn_index # => 2

Returns:

  • (Fixnum)


142
143
144
145
146
# File 'lib/vedeu/cursors/coordinate.rb', line 142

def dn_index
  return 0 if d_dn < 1

  d_dn - 1
end

#dn_positionFixnum Also known as: xn, yn

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 maximum coordinate for an area.

Examples:

# d = 2
# d_dn = 4 # represents width or height
dn # => 6

Returns:

  • (Fixnum)


34
35
36
37
38
# File 'lib/vedeu/cursors/coordinate.rb', line 34

def dn_position
  return 0 if d_dn <= 0

  d + d_dn
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 geometry for the interface.



88
89
90
# File 'lib/vedeu/cursors/coordinate.rb', line 88

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