Class: KeyValueWidget

Inherits:
Object
  • Object
show all
Defined in:
lib/delve/widgets/key_value.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, y, label, value) ⇒ KeyValueWidget

Returns a new instance of KeyValueWidget.


4
5
6
7
8
9
10
11
12
13
14
# File 'lib/delve/widgets/key_value.rb', line 4

def initialize(x, y, label, value)
  raise 'Cannot initialize key value widget when x is nil' unless x
  raise 'Cannot initialize key value widget when y is nil' unless y
  raise 'Cannot initialize key value widget when label is nil' unless label
  raise 'Cannot initialize key value widget when value is nil' unless value

  @x = x
  @y = y
  @label = label
  @value = value
end

Instance Attribute Details

#valueObject

Returns the value of attribute value.


2
3
4
# File 'lib/delve/widgets/key_value.rb', line 2

def value
  @value
end

Instance Method Details

#draw(display) ⇒ Object


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/delve/widgets/key_value.rb', line 16

def draw(display)
  raise 'Cannot draw text when display is nil' unless display

  x = @x
  @label.each_char do |c|
    display.draw x, @y, c
    x += 1
  end

  display.draw x, @y, ':'
  x += 1
  display.draw x, @y, ' '
  x += 1

  @value.each_char do |c|
    display.draw x, @y, c
    x += 1
  end
end