Class: RubyHome::IdentifierCache
- Inherits:
-
Object
- Object
- RubyHome::IdentifierCache
- Defined in:
- lib/ruby_home/identifier_cache.rb
Class Attribute Summary collapse
-
.accessories ⇒ Object
Returns the value of attribute accessories.
Class Method Summary collapse
- .add_accessory(accessory) ⇒ Object
- .add_characteristic(characteristic) ⇒ Object
- .add_service(service) ⇒ Object
- .characteristics ⇒ Object
- .find_characteristics(attributes) ⇒ Object
- .reset! ⇒ Object
- .services ⇒ Object
Class Attribute Details
.accessories ⇒ Object
Returns the value of attribute accessories.
4 5 6 |
# File 'lib/ruby_home/identifier_cache.rb', line 4 def accessories @accessories end |
Class Method Details
.add_accessory(accessory) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/ruby_home/identifier_cache.rb', line 30 def add_accessory(accessory) return true if accessories.include?(accessory) accessories << accessory.tap do |a| a.id = accessories.size + 1 end end |
.add_characteristic(characteristic) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/ruby_home/identifier_cache.rb', line 49 def add_characteristic(characteristic) return true if characteristics.include?(characteristic) service = characteristic.service service.characteristics << characteristic.tap do |c| c.instance_id = characteristic.accessory.next_available_instance_id end end |
.add_service(service) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/ruby_home/identifier_cache.rb', line 39 def add_service(service) return true if services.include?(service) accessory = service.accessory accessory.services << service.tap do |s| s.instance_id = accessory.next_available_instance_id end end |
.characteristics ⇒ Object
18 19 20 |
# File 'lib/ruby_home/identifier_cache.rb', line 18 def characteristics services.flat_map(&:characteristics) end |
.find_characteristics(attributes) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/ruby_home/identifier_cache.rb', line 22 def find_characteristics(attributes) characteristics.select do |characteristic| attributes.all? do |key, value| characteristic.send(key) == value end end end |
.reset! ⇒ Object
10 11 12 |
# File 'lib/ruby_home/identifier_cache.rb', line 10 def reset! @@accessories = [] end |
.services ⇒ Object
14 15 16 |
# File 'lib/ruby_home/identifier_cache.rb', line 14 def services accessories.flat_map(&:services) end |