Class: FSEvent::ValueIdDevice
- Inherits:
-
AbstractDevice
- Object
- AbstractDevice
- FSEvent::ValueIdDevice
- Defined in:
- lib/fsevent/valueiddevice.rb
Overview
valueiddevice.rb — value identity device
Copyright © 2014 National Institute of Advanced Industrial Science and Technology (AIST)
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <www.gnu.org/licenses/>.
Instance Attribute Summary
Attributes inherited from AbstractDevice
Instance Method Summary collapse
-
#initialize(device_name, target_device_name, status_name) ⇒ ValueIdDevice
constructor
A new instance of ValueIdDevice.
- #registered ⇒ Object
- #run(watched_status, changed_status) ⇒ Object
Methods inherited from AbstractDevice
#add_watch, #define_status, #del_watch, #inspect, #modify_status, #register_device, #set_elapsed_time, #undefine_status, #unregister_device, #unregistered
Constructor Details
#initialize(device_name, target_device_name, status_name) ⇒ ValueIdDevice
Returns a new instance of ValueIdDevice.
19 20 21 22 23 24 25 26 |
# File 'lib/fsevent/valueiddevice.rb', line 19 def initialize(device_name, target_device_name, status_name) super device_name @target_device_name = target_device_name @status_name = status_name @defined = false @old_value = nil @id = 0 end |
Instance Method Details
#registered ⇒ Object
28 29 30 |
# File 'lib/fsevent/valueiddevice.rb', line 28 def registered add_watch @target_device_name, @status_name, :immediate end |
#run(watched_status, changed_status) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/fsevent/valueiddevice.rb', line 32 def run(watched_status, changed_status) if watched_status.has_key?(@target_device_name) && watched_status[@target_device_name].has_key?(@status_name) value, id = watched_status[@target_device_name][@status_name] if !@defined @id += 1 define_status(@status_name, [value, @id]) @defined = true @old_value = value else if @old_value != value @id += 1 modify_status(@status_name, [value, @id]) @old_value = value end end else if @defined @id += 1 undefine_status(@status_name) @defined = false @old_value = nil end end end |