Class: TemperatureSensor

Inherits:
DigitalSensor show all
Defined in:
lib/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

Constructor Details

#initializeTemperatureSensor

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

#celsiusObject



14
15
16
# File 'lib/temperature_sensor.rb', line 14

def celsius
  @temperature
end

#fahrenheitObject



18
19
20
# File 'lib/temperature_sensor.rb', line 18

def fahrenheit
  @temperature * 9.0 / 5.0 + 32
end

#kelvinObject



22
23
24
# File 'lib/temperature_sensor.rb', line 22

def kelvin
  @temperature + 273.15
end

#read_dataObject



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

def read_data
  @temperature
end

#reaumurObject



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_sObject



30
31
32
# File 'lib/temperature_sensor.rb', line 30

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