Class: TemperatureConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/temperature_converter.rb

Class Method Summary collapse

Class Method Details

.commandlinetemp(input, printer_type) ⇒ Object



12
13
14
15
16
# File 'lib/temperature_converter.rb', line 12

def self.commandlinetemp(input, printer_type)
  temperature = CommandlineReader.reader(input)
  puts "Temperatuur uit commandline:"
  keuzePrinter(printer_type, temperature)
end

.filetemp(path, printer_type) ⇒ Object



18
19
20
21
22
# File 'lib/temperature_converter.rb', line 18

def self.filetemp(path,printer_type)
  temperature = FileReader.file_open(path)
  puts "Temperatuur uit file:"
  keuzePrinter(printer_type, temperature)
end

.keuzePrinter(printer_type, temperature) ⇒ Object

Converting and outputting in correct way



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/temperature_converter.rb', line 37

def self.keuzePrinter(printer_type, temperature)
  celc = Converter.to_celcius(temperature)
  fahr = Converter.to_fahrenheit(temperature)
  kelv = Converter.to_kelvin(temperature)
  case printer_type
    when "text"
      TextPrinter.printer(celc, fahr, kelv)
    when "json"
      JsonPrinter.printer(celc, fahr, kelv)
    when "html"
      HtmlPrinter.printer(celc, fahr, kelv)
    else
      puts "What the hell is #{printer_type}"
    end
end

.mqtttemp(host, port, username, password, printer_type) ⇒ Object



30
31
32
33
34
# File 'lib/temperature_converter.rb', line 30

def self.mqtttemp(host, port, username, password, printer_type)
  temperature = MqttReader.mqtt_open(host, port, username, password)
  puts "Temperatuur uit MQTT:"
  keuzePrinter(printer_type, temperature)
end

.urltemp(url, printer_type) ⇒ Object



24
25
26
27
28
# File 'lib/temperature_converter.rb', line 24

def self.urltemp(url, printer_type)
  temperature = UrlReader.url_open(url).to_f
  puts "Temperatuur uit url:"
  keuzePrinter(printer_type, temperature)
end