Skip to content

Commit

Permalink
T-22 Remane Celcius to Celsium (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
marian13 committed Mar 4, 2020
1 parent de3be5c commit e302a6c
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 100 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

![alt text](https://raw.githubusercontent.com/marian13/basic_temperature/master/logo.png)

Basic Temperature is a Ruby library which provides a simple value object to work with temperatures and allows to perform basic operations like conversion from Celcius to Kelvin, from Kelvin to Fahrenheit etc.
Basic Temperature is a Ruby library which provides a simple value object to work with temperatures and allows to perform basic operations like conversion from Celsius to Kelvin, from Kelvin to Fahrenheit etc.

### Features
- Provides a `BasicTemperature` class which encapsulates all information about a certain
Expand Down Expand Up @@ -45,11 +45,11 @@ Or install it yourself as:
```ruby
require 'basic_temperature'

temperature = BasicTemperature.new(degrees: 20, scale: :celcius)
# Scale can be one of celcius, kelvin or fahrenheit.
temperature = BasicTemperature.new(degrees: 20, scale: :celsius)
# Scale can be one of celsius, kelvin or fahrenheit.

temperature.to_celcius
# => 20 Celcius
temperature.to_celsius
# => 20 Celsius

temperature.to_kelvin
# => 293 Kelvin
Expand All @@ -67,17 +67,17 @@ temperature.to_scale(scale)
Temperatures can be compared between each other.

```ruby
temperature = BasicTemperature.new(degress: 0, scale: :celcius)
temperature = BasicTemperature.new(degress: 0, scale: :celsius)

other = BasicTemperature.new(degress: 0, scale: :celcius)
other = BasicTemperature.new(degress: 0, scale: :celsius)

temperature == other
# => true
```

When temperatures have different scales - conversion to common scale is handled under the hood.
```ruby
temperature = BasicTemperature.new(degress: 0, scale: :celcius)
temperature = BasicTemperature.new(degress: 0, scale: :celsius)

other = BasicTemperature.new(degress: 273.15, scale: :kelvin)

Expand Down
2 changes: 1 addition & 1 deletion basic_temperature.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
spec.summary = 'Value object for basic temperature operations.'
spec.description =
'Value object for basic temperature operations like ' \
'conversions from Celcius to Fahrenhait or Kelvin etc.'
'conversions from Celsius to Fahrenhait or Kelvin etc.'

spec.homepage = 'https://github.com/marian13/basic_temperature'

Expand Down
14 changes: 7 additions & 7 deletions lib/basic_temperature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'basic_temperature/version'

# Value Object for basic temperature operations like conversions from Celcius to Fahrenhait or Kelvin etc.
# Value Object for basic temperature operations like conversions from Celsius to Fahrenhait or Kelvin etc.
# rubocop:disable Metrics/ClassLength
class BasicTemperature
class InitializationArgumentsError < StandardError; end
Expand All @@ -13,7 +13,7 @@ class CoersionError < StandardError; end

SCALES =
[
CELCIUS = 'celcius',
CELSIUS = 'celsius',
FAHRENHEIT = 'fahrenheit',
KELVIN = 'kelvin'
]
Expand Down Expand Up @@ -46,7 +46,7 @@ def set_scale(scale)

def to_scale(scale)
case cast_scale(scale)
when CELCIUS
when CELSIUS
to_celsius
when FAHRENHEIT
to_fahrenheit
Expand All @@ -60,7 +60,7 @@ def to_scale(scale)
def to_celsius
return @to_celsius unless @to_celsius.nil?

return @to_celsius = self if self.scale == CELCIUS
return @to_celsius = self if self.scale == CELSIUS

degrees =
case self.scale
Expand All @@ -70,7 +70,7 @@ def to_celsius
self.degrees - 273.15
end

@to_celsius = BasicTemperature.new(degrees, CELCIUS)
@to_celsius = BasicTemperature.new(degrees, CELSIUS)
end

def to_fahrenheit
Expand All @@ -80,7 +80,7 @@ def to_fahrenheit

degrees =
case self.scale
when CELCIUS
when CELSIUS
self.degrees * (9 / 5r) + 32
when KELVIN
self.degrees * (9 / 5r) - 459.67
Expand All @@ -96,7 +96,7 @@ def to_kelvin

degrees =
case self.scale
when CELCIUS
when CELSIUS
self.degrees + 273.15
when FAHRENHEIT
(self.degrees + 459.67) * (5 / 9r)
Expand Down
Loading

0 comments on commit e302a6c

Please sign in to comment.