Class: DisplayMgr
- Inherits:
-
Object
- Object
- DisplayMgr
- Defined in:
- app/display.rb
Overview
Manage a list of display expressions.
Instance Method Summary collapse
- #[](index) ⇒ Object
- #add(frame, arg, fmt = nil) ⇒ Object
-
#all ⇒ Object
List all display items; return 0 if none.
-
#clear ⇒ Object
Delete all display expressions“”“.
-
#delete_index(display_number) ⇒ Object
Delete display expression i.
-
#display(frame) ⇒ Object
display any items that are active”‘.
- #enable_disable(display_number, b_enable_disable) ⇒ Object
-
#initialize ⇒ DisplayMgr
constructor
A new instance of DisplayMgr.
- #max ⇒ Object
- #nums ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize ⇒ DisplayMgr
Returns a new instance of DisplayMgr.
16 17 18 19 |
# File 'app/display.rb', line 16 def initialize @next = 0 @list = [] end |
Instance Method Details
#[](index) ⇒ Object
21 22 23 24 25 26 |
# File 'app/display.rb', line 21 def [](index) raise TypeError, "index #{index} should be a Fixnum, is #{index.class}" unless index.is_a?(Fixnum) @list.detect {|disp| disp.number == index } end |
#add(frame, arg, fmt = nil) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/display.rb', line 28 def add(frame, arg, fmt=nil) return nil unless frame begin eval(arg, frame.binding) rescue return nil end @next += 1 d = Display.new(frame, arg, fmt, @next) @list << d d end |
#all ⇒ Object
List all display items; return 0 if none
42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/display.rb', line 42 def all s = [] unless @list.empty? s << "Auto-display expressions now in effect: Num Enb Expression" @list.each do |display| s << display.format end end s end |
#clear ⇒ Object
Delete all display expressions“”“
55 56 57 |
# File 'app/display.rb', line 55 def clear @list = [] end |
#delete_index(display_number) ⇒ Object
Delete display expression i
60 61 62 63 64 65 66 67 68 |
# File 'app/display.rb', line 60 def delete_index(display_number) @list.each_with_index do |display, i| if display_number == display.number @list[i..i] = [] return true end end false end |
#display(frame) ⇒ Object
display any items that are active”‘
71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/display.rb', line 71 def display(frame) return unless frame s = [] sig = display_signature(frame) @list.each do |display| if display.enabled # && display.signature == sig s << display.to_s(frame) end end return s end |
#enable_disable(display_number, b_enable_disable) ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'app/display.rb', line 83 def enable_disable(display_number, b_enable_disable) @list.each do |display| if display_number == display.number display.enabled = b_enable_disable return true end end false end |
#max ⇒ Object
93 94 95 |
# File 'app/display.rb', line 93 def max @list.map{|disp| disp.number}.max end |
#nums ⇒ Object
97 98 99 |
# File 'app/display.rb', line 97 def nums @list.map{|disp| disp.number} end |
#size ⇒ Object
101 102 103 |
# File 'app/display.rb', line 101 def size @list.size end |