Created
November 26, 2012 13:23
-
-
Save shostakovich/4148171 to your computer and use it in GitHub Desktop.
Pressure Sensor
This file contains 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
class Sensor | |
OFFSET_IN_MBAR = 1000 | |
def current_pressure | |
OFFSET_IN_MBAR + random_pressure(); | |
end | |
private | |
def random_pressure | |
Random.rand(1200) | |
end | |
end | |
class Alarm | |
LOWPRESSURE_THRESHOLD = 1700 | |
HIGHPRESSURE_THRESHOLD = 2100 | |
def initialize | |
@sensor = Sensor.new | |
@alarm_on = false | |
end | |
def check | |
pressure_value = @sensor.current_pressure | |
if (pressure_value < LOWPRESSURE_THRESHOLD || HIGHPRESSURE_THRESHOLD < pressure_value) | |
@alarm_on = true | |
end | |
end | |
def alarm_on? | |
@alarm_on | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Refactor + Test the code