class HG::Weather::Temperature
Attributes
celsius[RW]
fahrenheit[RW]
Public Class Methods
new(temperature, format = :c)
click to toggle source
# File lib/hg/weather/temperature.rb, line 8 def initialize temperature, format = :c return if temperature.nil? temperature = temperature.to_f if format == :c @celsius = temperature @fahrenheit = ((temperature * 1.8) + 32).round(2) else @fahrenheit = temperature @celsius = ((temperature - 32) / 1.8).round(2) end end
Public Instance Methods
get_with_format()
click to toggle source
# File lib/hg/weather/temperature.rb, line 21 def get_with_format case Weather.temperature when :celsius @celsius when :fahrenheit @fahrenheit end end
inspect()
click to toggle source
# File lib/hg/weather/temperature.rb, line 30 def inspect self.to_s end
to_f()
click to toggle source
# File lib/hg/weather/temperature.rb, line 38 def to_f self.get_with_format end
to_i()
click to toggle source
# File lib/hg/weather/temperature.rb, line 42 def to_i self.get_with_format.to_i end
to_s()
click to toggle source
# File lib/hg/weather/temperature.rb, line 34 def to_s "#{self.get_with_format}ยบ #{Weather.temperature.to_s[0].upcase}" end