Class: TemperatureSensor
Overview
TemperatureSensor - temperature sensing receptor
Instance Method Summary
collapse
one_wire_file
Methods inherited from Receptor
#model_name, #name
Constructor Details
Returns a new instance of TemperatureSensor.
7
8
9
|
# File 'lib/temperature_sensor.rb', line 7
def initialize
@temperature = read_data
end
|
Instance Method Details
#celsius ⇒ Object
14
15
16
|
# File 'lib/temperature_sensor.rb', line 14
def celsius
@temperature
end
|
#fahrenheit ⇒ Object
18
19
20
|
# File 'lib/temperature_sensor.rb', line 18
def fahrenheit
@temperature * 9.0 / 5.0 + 32
end
|
#kelvin ⇒ Object
22
23
24
|
# File 'lib/temperature_sensor.rb', line 22
def kelvin
@temperature + 273.15
end
|
#read_data ⇒ Object
11
12
13
|
# File 'lib/temperature_sensor.rb', line 11
def read_data
@temperature
end
|
#reaumur ⇒ Object
26
27
28
|
# File 'lib/temperature_sensor.rb', line 26
def reaumur
@temperature * 0.8
end
|
#temperature(mode = :celsius) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/temperature_sensor.rb', line 34
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
30
31
32
|
# File 'lib/temperature_sensor.rb', line 30
def to_s
sprintf "%5.2f°C", @temperature
end
|