Skip to content

Instantly share code, notes, and snippets.

@bragboy
Created December 31, 2015 12:42
Show Gist options
  • Select an option

  • Save bragboy/eb8d7143d10f7d1e4a9a to your computer and use it in GitHub Desktop.

Select an option

Save bragboy/eb8d7143d10f7d1e4a9a to your computer and use it in GitHub Desktop.
#models/corridor.rb
class Corridor
attr_accessor :lights
attr_accessor :air_conditioners
def initialize
@lights = [Instrument.new(STATUS_OFF, DEFAULT_UNITS_LIGHTS)]
@air_conditioners = [Instrument.new(STATUS_OFF, DEFAULT_UNITS_AC)]
@movement = false
end
def current_status
status = ''
@lights.each_with_index do |light, i|
status << " Light #{i+1}: #{light.status}" + "\n"
end
@air_conditioners.each_with_index do |ac, i|
status << " AC #{i+1}: #{ac.status}" + "\n"
end
status
end
def move
@movement = true
end
def unmove
@movement = false
end
def was_moving?
@movement
end
def power_consumption
pc = 0
pc += @lights.inject(0) {|r, light| r + light.power_consumption}
pc += @air_conditioners.inject(0) {|r, ac| r + ac.power_consumption}
pc
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment