Class: RETerm::Components::Rocker

Inherits:
RETerm::Component show all
Includes:
RETerm::ComponentInput
Defined in:
lib/reterm/components/rocker.rb

Overview

Rocker component, allowing use to select one of several values

Constant Summary

Constants included from RETerm::ComponentInput

RETerm::ComponentInput::DEC_CONTROLS, RETerm::ComponentInput::INC_CONTROLS, RETerm::ComponentInput::QUIT_CONTROLS

Instance Attribute Summary collapse

Attributes inherited from RETerm::Component

#window

Instance Method Summary collapse

Methods included from RETerm::ComponentInput

#handle_input

Methods inherited from RETerm::Component

#colored?, #colors=, #finalize!

Constructor Details

#initialize(args = {}) ⇒ Rocker

Initialize the Rocker component

Examples:

using the Rocker

win    = Window.new
rocker = Rocker.new
win.component = rocker
rocker.values = ['Foo', 'Bar', 'Baz']
val = rocker.activate!

Parameters:

  • args (Hash) (defaults to: {})

    rocker params



20
21
22
23
24
25
# File 'lib/reterm/components/rocker.rb', line 20

def initialize(args={})
  @values = []
  @index  = nil
  @labels = true
  @index  = 0
end

Instance Attribute Details

#indexObject

Returns the value of attribute index.



7
8
9
# File 'lib/reterm/components/rocker.rb', line 7

def index
  @index
end

#labelsObject

Returns the value of attribute labels.



7
8
9
# File 'lib/reterm/components/rocker.rb', line 7

def labels
  @labels
end

#valuesObject

Returns the value of attribute values.



7
8
9
# File 'lib/reterm/components/rocker.rb', line 7

def values
  @values
end

Instance Method Details

#activatable?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/reterm/components/rocker.rb', line 31

def activatable?
  true
end

#activate!Object



35
36
37
38
39
# File 'lib/reterm/components/rocker.rb', line 35

def activate!
  refresh_win
  handle_input
  @values[@index]
end

#draw!Object



27
28
29
# File 'lib/reterm/components/rocker.rb', line 27

def draw!
  refresh_win
end