Class: MiOS::Interface

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/mios/interface.rb

Instance Method Summary collapse

Constructor Details

#initialize(base_uri) ⇒ Interface

Returns a new instance of Interface.



10
11
12
# File 'lib/mios/interface.rb', line 10

def initialize(base_uri)
  @client = Client.new(base_uri)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



46
47
48
# File 'lib/mios/interface.rb', line 46

def method_missing(method, *args)
  attributes[method.to_s] || super
end

Instance Method Details

#attributesObject



42
43
44
# File 'lib/mios/interface.rb', line 42

def attributes
  @attributes ||= load_attributes
end

#categoriesObject



18
19
20
# File 'lib/mios/interface.rb', line 18

def categories
  @categories ||= CategoryCollection.new(raw_data['category_filter'])
end

#device_namesObject



38
39
40
# File 'lib/mios/interface.rb', line 38

def device_names
  devices.map(&:name)
end

#devicesObject



22
23
24
# File 'lib/mios/interface.rb', line 22

def devices
  @devices ||= raw_data['devices'].collect { |d| Device.new(self, d) }
end

#devices_for_label(label) ⇒ Object



26
27
28
# File 'lib/mios/interface.rb', line 26

def devices_for_label(label)
  devices.select { |device| device.category && device.category.label == label }
end

#refresh!Object



14
15
16
# File 'lib/mios/interface.rb', line 14

def refresh!
  @raw_data, @devices, @attributes, @categories, @rooms, @scenes = nil
end

#roomsObject



30
31
32
# File 'lib/mios/interface.rb', line 30

def rooms
  @rooms ||= raw_data['rooms'].collect { |r| Room.new(r['id'], r['name']) }
end

#scenesObject



34
35
36
# File 'lib/mios/interface.rb', line 34

def scenes
  @scenes ||= raw_data['scenes'].collect { |s| Scene.new(self, s['id'], s['name']) }
end