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.
17 18 19 20 |
# File 'app/display.rb', line 17 def initialize @next = 0 @list = [] end |
Instance Method Details
#[](index) ⇒ Object
22 23 24 25 26 27 |
# File 'app/display.rb', line 22 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
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/display.rb', line 29 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
43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/display.rb', line 43 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“”“
56 57 58 |
# File 'app/display.rb', line 56 def clear @list = [] end |
#delete_index(display_number) ⇒ Object
Delete display expression i
61 62 63 64 65 66 67 68 69 |
# File 'app/display.rb', line 61 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”‘
72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/display.rb', line 72 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
84 85 86 87 88 89 90 91 92 |
# File 'app/display.rb', line 84 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
94 95 96 |
# File 'app/display.rb', line 94 def max @list.map{|disp| disp.number}.max end |
#nums ⇒ Object
98 99 100 |
# File 'app/display.rb', line 98 def nums @list.map{|disp| disp.number} end |
#size ⇒ Object
102 103 104 |
# File 'app/display.rb', line 102 def size @list.size end |