Permalink
Browse files

added the Ruby version of TirePressureMonitoringSystem original exercise

  • Loading branch information...
1 parent 2e297ad commit 01b61b24f2105c2712e93cfd5d8176c67811cd3d Sam Serpoosh committed Sep 6, 2012
Showing with 39 additions and 0 deletions.
  1. +24 −0 TDDMicroExercises/Ruby/alarm.rb
  2. +15 −0 TDDMicroExercises/Ruby/sensor.rb
@@ -0,0 +1,24 @@
+require_relative "./sensor"
+
+class Alarm
+ LOWPRESSURETHRESHOLD = 17
+ HIGHPRESSURETHRESHOLD = 21
+
+ def initialize
+ @sensor = Sensor.new
+ @alarm_on = false
+ @alarm_count = 0
+ end
+
+ def check
+ psi_pressure_value = @sensor.pop_next_pressure_psi_value
+ if psi_pressure_value < LOWPRESSURETHRESHOLD || HIGHPRESSURETHRESHOLD < psi_pressure_value
+ @alarm_on = true
+ @alarm_count += 1
+ end
+ end
+
+ def alarm_on
+ return @alarm_on
+ end
+end
@@ -0,0 +1,15 @@
+class Sensor
+ OFFSET = 16;
+
+ def pop_next_pressure_psi_value
+ pressure_telemetry_value = sample_pressure
+ OFFSET + pressure_telemetry_value;
+ end
+
+ def sample_pressure
+ #placeholder implementation that
+ #simulate a real sensor in a real tire
+ pressure_telemetry_value = 6 * rand(5) * rand(4)
+ pressure_telemetry_value
+ end
+end

0 comments on commit 01b61b2

Please sign in to comment.