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.



12
13
14
# File 'lib/mios/interface.rb', line 12

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



48
49
50
# File 'lib/mios/interface.rb', line 48

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

Instance Method Details

#attributesObject



44
45
46
# File 'lib/mios/interface.rb', line 44

def attributes
  @attributes ||= load_attributes
end

#categoriesObject



20
21
22
# File 'lib/mios/interface.rb', line 20

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

#device_namesObject



40
41
42
# File 'lib/mios/interface.rb', line 40

def device_names
  devices.map(&:name)
end

#devicesObject



24
25
26
# File 'lib/mios/interface.rb', line 24

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

#devices_for_label(label) ⇒ Object



28
29
30
# File 'lib/mios/interface.rb', line 28

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

#refresh!Object



16
17
18
# File 'lib/mios/interface.rb', line 16

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

#roomsObject



32
33
34
# File 'lib/mios/interface.rb', line 32

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

#scenesObject



36
37
38
# File 'lib/mios/interface.rb', line 36

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