Class: Vedeu::BoundingArea

Inherits:
Object
  • Object
show all
Defined in:
lib/vedeu/geometry/bounding_area.rb

Overview

Provides coordinates based on the height and width provided. Coordinates always start from 1, 1.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(height, width) ⇒ Vedeu::BoundingArea

Returns an instance of BoundingArea.

Parameters:



16
17
18
19
# File 'lib/vedeu/geometry/bounding_area.rb', line 16

def initialize(height, width)
  @height = height
  @width  = width
end

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.



8
9
10
# File 'lib/vedeu/geometry/bounding_area.rb', line 8

def height
  @height
end

#widthObject (readonly)

Returns the value of attribute width.



8
9
10
# File 'lib/vedeu/geometry/bounding_area.rb', line 8

def width
  @width
end

Instance Method Details

#bottom(offset = 0) ⇒ Fixnum Also known as: yn

Returns the bottom line (yn) coordinate for the console.

Examples:

# height = 20

bottom     # => 20
bottom(5)  # => 15
bottom(-5) # => 20
bottom(25) # => 1

Parameters:

  • offset (Fixnum) (defaults to: 0)

    When provided, returns the bottom coordinate minus the offset.

Returns:



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/vedeu/geometry/bounding_area.rb', line 61

def bottom(offset = 0)
  if offset >= height
    1

  elsif offset < 0
    height

  else
    height - offset

  end
end

#left(offset = 0) ⇒ Fixnum Also known as: x

Returns the leftmost column (x) coordinate for the console.

Examples:

# width = 40

left     # => 1
left(5)  # => 6
left(-5) # => 1
left(45) # => 40

Parameters:

  • offset (Fixnum) (defaults to: 0)

    When provided, returns the left coordinate plus the offset.

Returns:



88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/vedeu/geometry/bounding_area.rb', line 88

def left(offset = 0)
  if offset >= width
    width

  elsif offset <= 1
    1

  else
    1 + offset

  end
end

#right(offset = 0) ⇒ Fixnum Also known as: xn

Returns the rightmost column (yn) coordinate for the console.

Examples:

# width = 40

right     # => 40
right(5)  # => 35
right(-5) # => 40
right(45) # => 1

Parameters:

  • offset (Fixnum) (defaults to: 0)

    When provided, returns the right coordinate minus the offset.

Returns:



115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/vedeu/geometry/bounding_area.rb', line 115

def right(offset = 0)
  if offset >= width
    1

  elsif offset < 0
    width

  else
    width - offset

  end
end

#top(offset = 0) ⇒ Fixnum Also known as: y

Returns the top line (y) coordinate for the console.

Examples:

# height = 20

top     # => 1
top(5)  # => 6
top(-5) # => 1
top(25) # => 20

Parameters:

  • offset (Fixnum) (defaults to: 0)

    When provided, returns the top coordinate plus the offset.

Returns:



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/vedeu/geometry/bounding_area.rb', line 34

def top(offset = 0)
  if offset >= height
    height

  elsif offset <= 1
    1

  else
    1 + offset

  end
end