Class: Sparky
- Inherits:
-
Object
- Object
- Sparky
- Defined in:
- lib/sparky.rb
Constant Summary collapse
- @@run_pins =
[[Switchy::PINS::C4, Switchy::PINS::C2], [Switchy::PINS::C5, Switchy::PINS::D0 ]]
- @@fail_pins =
[[Switchy::PINS::C6, Switchy::PINS::D1], [Switchy::PINS::C7, Switchy::PINS::D2]]
- @@pending_pins =
[[Switchy::PINS::B7, Switchy::PINS::D3], [Switchy::PINS::B6, Switchy::PINS::D4]]
- @@pass_pins =
[[Switchy::PINS::B3, Switchy::PINS::D7, Switchy::PINS::B5, Switchy::PINS::D5], [Switchy::PINS::B2, Switchy::PINS::B0, Switchy::PINS::B4, Switchy::PINS::D6]]
- @@reset_pins =
[[Switchy::PINS::C4, Switchy::PINS::C2, Switchy::PINS::C6, Switchy::PINS::D1, Switchy::PINS::B7, Switchy::PINS::D3, Switchy::PINS::B5, Switchy::PINS::B3, Switchy::PINS::D7, Switchy::PINS::D5]]
Instance Attribute Summary collapse
-
#failed ⇒ Object
Sets the attribute failed.
-
#passed ⇒ Object
Sets the attribute passed.
-
#pending ⇒ Object
Returns the value of attribute pending.
Instance Method Summary collapse
- #clear_failed ⇒ Object
- #clear_pass ⇒ Object
- #clear_pending ⇒ Object
- #clear_pin(pin) ⇒ Object
- #clear_pins(pins) ⇒ Object
- #clear_run ⇒ Object
- #example_failed ⇒ Object
- #example_passed ⇒ Object
- #example_pending ⇒ Object
- #fail ⇒ Object (also: #failed)
- #finish_run ⇒ Object
-
#initialize ⇒ Sparky
constructor
A new instance of Sparky.
- #pass ⇒ Object (also: #passed)
- #pin(set, idx) ⇒ Object
- #reset ⇒ Object
- #run ⇒ Object
- #set_pin(pin) ⇒ Object
- #set_pins(pins) ⇒ Object
- #start_run ⇒ Object
Constructor Details
#initialize ⇒ Sparky
Returns a new instance of Sparky.
20 21 22 23 |
# File 'lib/sparky.rb', line 20 def initialize @passed, @failed, @pending = -1, -1, -1 @switchy = Switchy.new end |
Instance Attribute Details
#failed=(value) ⇒ Object
Sets the attribute failed
7 8 9 |
# File 'lib/sparky.rb', line 7 def failed=(value) @failed = value end |
#passed=(value) ⇒ Object
Sets the attribute passed
7 8 9 |
# File 'lib/sparky.rb', line 7 def passed=(value) @passed = value end |
#pending ⇒ Object
Returns the value of attribute pending.
7 8 9 |
# File 'lib/sparky.rb', line 7 def pending @pending end |
Instance Method Details
#clear_failed ⇒ Object
63 64 65 |
# File 'lib/sparky.rb', line 63 def clear_failed clear_pins @@fail_pins end |
#clear_pass ⇒ Object
54 55 56 |
# File 'lib/sparky.rb', line 54 def clear_pass clear_pins @@pass_pins end |
#clear_pending ⇒ Object
71 72 73 |
# File 'lib/sparky.rb', line 71 def clear_pending clear_pins @@pending_pins end |
#clear_pin(pin) ⇒ Object
39 40 41 |
# File 'lib/sparky.rb', line 39 def clear_pin(pin) @switchy.set_pin pin.first, 0 end |
#clear_pins(pins) ⇒ Object
43 44 45 46 47 |
# File 'lib/sparky.rb', line 43 def clear_pins(pins) pins.first.each do |pin| @switchy.set_pin pin, 0 end end |
#clear_run ⇒ Object
79 80 81 |
# File 'lib/sparky.rb', line 79 def clear_run clear_pins @@run_pins end |
#example_failed ⇒ Object
109 110 111 112 113 |
# File 'lib/sparky.rb', line 109 def example_failed clear_pin pin(:failed, @failed % 2) if @failed >= 0 @failed += 1 set_pin pin(:failed, @failed % 2) end |
#example_passed ⇒ Object
103 104 105 106 107 |
# File 'lib/sparky.rb', line 103 def example_passed clear_pin pin(:passed, @passed % 4) if @passed >= 0 @passed += 1 set_pin pin(:passed, @passed % 4) end |
#example_pending ⇒ Object
115 116 117 118 119 |
# File 'lib/sparky.rb', line 115 def example_pending clear_pin pin(:pending, @pending % 2) if @pending >= 0 @pending += 1 set_pin pin(:pending, @pending % 2) end |
#fail ⇒ Object Also known as: failed
58 59 60 |
# File 'lib/sparky.rb', line 58 def fail set_pins @@fail_pins end |
#finish_run ⇒ Object
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/sparky.rb', line 92 def finish_run reset if @failed > -1 failed elsif @pending > -1 pending else pass end end |
#pass ⇒ Object Also known as: passed
49 50 51 |
# File 'lib/sparky.rb', line 49 def pass set_pins @@pass_pins end |
#pin(set, idx) ⇒ Object
121 122 123 124 125 126 127 128 |
# File 'lib/sparky.rb', line 121 def pin(set, idx) pins = case set when :passed then @@pass_pins when :failed then @@fail_pins when :pending then @@pending_pins end [ pins.first[idx], pins.last[idx] ] end |
#reset ⇒ Object
83 84 85 |
# File 'lib/sparky.rb', line 83 def reset clear_pins @@reset_pins end |
#run ⇒ Object
75 76 77 |
# File 'lib/sparky.rb', line 75 def run set_pins @@run_pins end |
#set_pin(pin) ⇒ Object
34 35 36 37 |
# File 'lib/sparky.rb', line 34 def set_pin(pin) @switchy.set_pin pin.first, 1 @switchy.set_pin pin.last, 0 end |
#set_pins(pins) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/sparky.rb', line 25 def set_pins(pins) pins.first.each do |pin| @switchy.set_pin pin, 1 end pins.last.each do |pin| @switchy.set_pin pin, 0 end end |
#start_run ⇒ Object
87 88 89 90 |
# File 'lib/sparky.rb', line 87 def start_run reset run end |