Sha256: 5974087ce0174ad2358bf3dad7a0b1f91b57f7c481ff057d54fccefaf7fe279c

Contents?: true

Size: 731 Bytes

Versions: 5

Compression:

Stored size: 731 Bytes

Contents

require 'w1temp'

module MilkMaid
  class SensorException < RuntimeError; end

  class TemperatureSensor
    def initialize
      @sensor = Temperature.new

      fail ::MilkMaid::SensorException.new 'Sensor not available' unless @sensor.name
    end

    def name
      return "No sensor attached" unless @sensor.name
      @sensor.name
    end

    def reading
      return "Reading: No sensor attached" unless @sensor.reading
      @sensor.reading
    end
  end

  class MockTemperatureSensor
    def initialize(low_temp, high_temp)
      @low_temp = low_temp.to_i
      @high_temp = high_temp.to_i
    end

    def name
      'MockTemperatureSensor'
    end

    def reading
      rand(@low_temp..@high_temp)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
milk_maid-0.4.0 lib/milk_maid/temperature_sensor.rb
milk_maid-0.3.0 lib/milk_maid/temperature_sensor.rb
milk_maid-0.2.8 lib/milk_maid/temperature_sensor.rb
milk_maid-0.2.7 lib/milk_maid/temperature_sensor.rb
milk_maid-0.2.6 lib/milk_maid/temperature_sensor.rb