Class: Vedeu::Geometry

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

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Geometry

Returns a new instance of Geometry.



10
11
12
# File 'lib/vedeu/support/geometry.rb', line 10

def initialize(attrs = {})
  @attrs = attrs
end

Instance Method Details

#bottomObject



74
75
76
# File 'lib/vedeu/support/geometry.rb', line 74

def bottom
  top + height
end

#centreObject



46
47
48
# File 'lib/vedeu/support/geometry.rb', line 46

def centre
  [(terminal_height / 2), (terminal_width / 2)]
end

#centre_xObject



54
55
56
# File 'lib/vedeu/support/geometry.rb', line 54

def centre_x
  centre.last
end

#centre_yObject



50
51
52
# File 'lib/vedeu/support/geometry.rb', line 50

def centre_y
  centre.first
end

#centredObject



42
43
44
# File 'lib/vedeu/support/geometry.rb', line 42

def centred
  @centred ||= attrs_centred
end

#heightObject



22
23
24
# File 'lib/vedeu/support/geometry.rb', line 22

def height
  @height ||= attrs_height
end

#leftObject



66
67
68
69
70
71
72
# File 'lib/vedeu/support/geometry.rb', line 66

def left
  if centred
    centre_x - (width / 2)
  else
    x
  end
end

#origin(index = 0) ⇒ Object



14
15
16
# File 'lib/vedeu/support/geometry.rb', line 14

def origin(index = 0)
  Esc.set_position(virtual_y(index), virtual_x)
end

#positionObject



82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/vedeu/support/geometry.rb', line 82

def position
  {
    y:       top,
    x:       left,
    height:  height,
    width:   width,
    centred: centred,
    top:     top,
    bottom:  bottom,
    left:    left,
    right:   right,
  }
end

#rightObject



78
79
80
# File 'lib/vedeu/support/geometry.rb', line 78

def right
  left + width
end

#terminal_heightObject



18
19
20
# File 'lib/vedeu/support/geometry.rb', line 18

def terminal_height
  @terminal_height ||= attrs_terminal_height
end

#terminal_widthObject



34
35
36
# File 'lib/vedeu/support/geometry.rb', line 34

def terminal_width
  @terminal_width ||= attrs_terminal_width
end

#topObject



58
59
60
61
62
63
64
# File 'lib/vedeu/support/geometry.rb', line 58

def top
  if centred
    centre_y - (height / 2)
  else
    y
  end
end

#widthObject



38
39
40
# File 'lib/vedeu/support/geometry.rb', line 38

def width
  @width ||= attrs_width
end

#xObject



30
31
32
# File 'lib/vedeu/support/geometry.rb', line 30

def x
  @x ||= attrs_x
end

#yObject



26
27
28
# File 'lib/vedeu/support/geometry.rb', line 26

def y
  @y ||= attrs_y
end