Created
December 7, 2012 23:47
-
-
Save jgorset/4237588 to your computer and use it in GitHub Desktop.
Rooms...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Load all rooms. | |
# | |
# Returns an array of hashes describing each room. | |
def all | |
devices = Device.all | |
rooms = [] | |
# Go through each device, check wich room it belongs | |
# do, if the room does not exist, add it to rooms, if | |
# just add this device to the list of devices | |
devices.each do |device| | |
if rooms.key? device.room | |
room = rooms[device.room] | |
else | |
room = rooms[device.room] = new device.room | |
end | |
room.devices << device | |
end | |
rooms | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment