Class: Datastore

Inherits:
HObject show all
Defined in:
lib/lights/datastore.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from HObject

#to_json

Constructor Details

#initialize(data = {}) ⇒ Datastore

Returns a new instance of Datastore.



13
14
15
16
17
18
19
20
21
# File 'lib/lights/datastore.rb', line 13

def initialize(data = {})
  @lights = BulbList.new(data["lights"]) 
  @groups = GroupList.new(data["groups"])
  @config = HueConfig.new(data["config"])
  @schedules = ScheduleList.new(data["schedules"])
  @scenes = SceneList.new(data["scenes"])
  @rules = RuleList.new(data["rules"])
  @sensors = SensorList.new(data["sensors"])
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



11
12
13
# File 'lib/lights/datastore.rb', line 11

def config
  @config
end

#groupsObject (readonly)

Returns the value of attribute groups.



11
12
13
# File 'lib/lights/datastore.rb', line 11

def groups
  @groups
end

#lightsObject (readonly)

Returns the value of attribute lights.



11
12
13
# File 'lib/lights/datastore.rb', line 11

def lights
  @lights
end

#rulesObject (readonly)

Returns the value of attribute rules.



11
12
13
# File 'lib/lights/datastore.rb', line 11

def rules
  @rules
end

#scenesObject (readonly)

Returns the value of attribute scenes.



11
12
13
# File 'lib/lights/datastore.rb', line 11

def scenes
  @scenes
end

#schedulesObject (readonly)

Returns the value of attribute schedules.



11
12
13
# File 'lib/lights/datastore.rb', line 11

def schedules
  @schedules
end

#sensorsObject (readonly)

Returns the value of attribute sensors.



11
12
13
# File 'lib/lights/datastore.rb', line 11

def sensors
  @sensors
end

Instance Method Details

#dataObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/lights/datastore.rb', line 33

def data
  data = {}
  data["lights"] = @lights.data if !@lights.data.empty?
  data["groups"] = @groups.data if !@groups.data.empty?
  data["config"] = @config.data if !@config.data.empty?
  data["schedules"] = @schedules.data if !@schedules.data.empty?
  data["scenes"] = @scenes.data if !@scenes.data.empty?
  data["rules"] = @rules.data if !@rules.data.empty?
  data["sensors"] = @sensors.data if !@sensors.data.empty?
  data
end

#listObject



23
24
25
26
27
28
29
30
31
# File 'lib/lights/datastore.rb', line 23

def list
  @lights.list + \
    @groups.list + \
    [@config] + \
    @schedules.list + \
    @scenes.list + \
    @rules.list + \
    @sensors.list
end