Class: IoT::TemperatureSensor

Inherits:
DigitalSensor show all
Defined in:
lib/iot/temperature_sensor.rb

Overview

TemperatureSensor - temperature sensing receptor

Instance Method Summary collapse

Methods inherited from DigitalReceptor

one_wire_file

Methods inherited from Receptor

#model_name, #name, #read

Constructor Details

#initializeTemperatureSensor

Returns a new instance of TemperatureSensor.



8
9
10
# File 'lib/iot/temperature_sensor.rb', line 8

def initialize
  @temperature = read_data
end

Instance Method Details

#celsiusObject



16
17
18
# File 'lib/iot/temperature_sensor.rb', line 16

def celsius
  @temperature
end

#fahrenheitObject



20
21
22
# File 'lib/iot/temperature_sensor.rb', line 20

def fahrenheit
  @temperature * 9.0 / 5.0 + 32
end

#kelvinObject



24
25
26
# File 'lib/iot/temperature_sensor.rb', line 24

def kelvin
  @temperature + 273.15
end

#read_dataObject



12
13
14
# File 'lib/iot/temperature_sensor.rb', line 12

def read_data
  @temperature
end

#reaumurObject



28
29
30
# File 'lib/iot/temperature_sensor.rb', line 28

def reaumur
  @temperature * 0.8
end

#temperature(mode = :celsius) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/iot/temperature_sensor.rb', line 36

def temperature(mode=:celsius)
  case mode
  when :celsius
    celsius
  when :fahrenheit
    fahrenheit
  when :kelvin
    kelvin
  when :reaumur
    reaumur
  else
    celsius
  end
end

#to_sObject



32
33
34
# File 'lib/iot/temperature_sensor.rb', line 32

def to_s
  sprintf "%5.2f°C", @temperature
end