forked from bitmakerlabs/learn_ruby_rspec
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0018774
commit cddb52b
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
class Temperature | ||
def initialize(temphash) | ||
@temp = temphash[:f] || temphash[:c] | ||
@unit = temphash.keys[0] | ||
end | ||
|
||
def to_fahrenheit | ||
return @temp if @unit == :f | ||
((@temp * 9/5) + 32).round(1) | ||
end | ||
|
||
def to_celsius | ||
return @temp if @unit == :c | ||
((@temp - 32) * 5/9).ceil | ||
end | ||
|
||
def self.in_celsius(temp) | ||
Temperature.new({c: temp}) | ||
end | ||
|
||
def self.in_fahrenheit(temp) | ||
Temperature.new({f: temp}) | ||
end | ||
|
||
|
||
end | ||
|
||
class Celsius < Temperature | ||
def initialize(temp) | ||
@temp = temp | ||
@unit = :c | ||
end | ||
end | ||
|
||
class Fahrenheit < Temperature | ||
def initialize(temp) | ||
@temp = temp | ||
@unit = :f | ||
end | ||
end | ||
|
||
=begin | ||
def ftoc(temp) | ||
( ( temp - 32 ) * 5/9 ).ceil | ||
end | ||
def ctof(temp) | ||
((temp * 9/5)+ 32).round(1) | ||
end | ||
=end |