Class: BulbList

Inherits:
Object
  • Object
show all
Defined in:
lib/lights/bulblist.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ BulbList

Returns a new instance of BulbList.



6
7
8
9
10
# File 'lib/lights/bulblist.rb', line 6

def initialize(data = {})
  @bulbs = []
  data.each{|id,value| @bulbs << Bulb.new(id,value)} if data
  @data = data
end

Instance Attribute Details

#bulbsObject (readonly)

Returns the value of attribute bulbs.



5
6
7
# File 'lib/lights/bulblist.rb', line 5

def bulbs
  @bulbs
end

Instance Method Details

#dataObject



12
13
14
15
16
# File 'lib/lights/bulblist.rb', line 12

def data
  data = @data
  @bulbs.each {|b| data[b.id] = b.data} if @bulbs
  data
end

#to_json(options = {}) ⇒ Object



18
19
20
# File 'lib/lights/bulblist.rb', line 18

def to_json(options={})
  data.to_json
end