Class: IoT::TemperatureSensor
Overview
TemperatureSensor - temperature sensing receptor
Instance Method Summary
collapse
one_wire_file
Methods inherited from Receptor
#model_name, #name, #read
Constructor Details
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
#celsius ⇒ Object
16
17
18
|
# File 'lib/iot/temperature_sensor.rb', line 16
def celsius
@temperature
end
|
#fahrenheit ⇒ Object
20
21
22
|
# File 'lib/iot/temperature_sensor.rb', line 20
def fahrenheit
@temperature * 9.0 / 5.0 + 32
end
|
#kelvin ⇒ Object
24
25
26
|
# File 'lib/iot/temperature_sensor.rb', line 24
def kelvin
@temperature + 273.15
end
|
#read_data ⇒ Object
12
13
14
|
# File 'lib/iot/temperature_sensor.rb', line 12
def read_data
@temperature
end
|
#reaumur ⇒ Object
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_s ⇒ Object
32
33
34
|
# File 'lib/iot/temperature_sensor.rb', line 32
def to_s
sprintf "%5.2f°C", @temperature
end
|