tempture-convertor 0.1.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +18 -18
  3. data/lib/tempture_convertor.rb +6 -27
  4. metadata +3 -59
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9ed8a313eed1f3b5d8943eccb7c202442f88edd325ab8a22887d05ca9eee425a
4
- data.tar.gz: 3d30504a1ad9abd073f51a6782f2087f824a07d8ff59b1c309b64601521055d5
3
+ metadata.gz: f8dc1c1e1024ee0ffcd4c1846f7c232f2e73a83888854a7ca8b3ffa7e4ccdbc3
4
+ data.tar.gz: 535c2098075224fb2a194de03ad692c556a3a23df0e8d6014f2eb11233198c6d
5
5
  SHA512:
6
- metadata.gz: 40e690dd017c1766c0e73e2d342f8368380de15994db96de871e77de60c228bf54f324784e536801f869861608b177f2073aa209aeb01ac2957424da20251d1b
7
- data.tar.gz: a520c6496e9d983f7d5f47424142a5a70c6191a7972dabeaf2e3fa92ca20c51dddc17cb4797c3bda8f6216e96c0bab7d76d60252921223c1e4402cb41e72decf
6
+ metadata.gz: 809d556edd12b7ce8fad7e93aeb7f09812f99b4bbb060351eb6e51846c29e157435eeaa3b3a292232302941f7cae7d897e8835c7ca745fdacb6d5fe42d3789bf
7
+ data.tar.gz: 7353078c2deb97673a6fd8356774b6cbf64f62e3563e33771e13b52eb1c60d272f141144064dc4a20f304aea9067bfb15ae604bfeec16f0acfdb76d26c7d2038
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Temperature Convertor
2
2
 
3
- convert temperature from fehrenheit or kelvin to celsius
3
+ Convert temperature between fehrenheit, kelvin and celsius
4
4
 
5
5
 
6
6
  ## Detail
@@ -9,12 +9,12 @@ The "Temperature" class stores and controls the value and convert function
9
9
 
10
10
  **Constructor**
11
11
 
12
- > ` def initialize(temperature, mode) `
12
+ > def initialize(temperature, mode)
13
13
 
14
- The initialization process retrieve temperature user input and specific Temperature Mode and store temperature in celsius form.<br>
15
- [param] temperature: float --> the temperature value<br>
16
- [param] mode: TemperatureMode --> the temperature unit (Fahrenheit, Celsius or Kelvin)<br>
17
- Note the TemperatureMode is an enumerate that holds value of TemperatureMode::Celsius, TemperatureMode::Fahrenheit or TemperatureMode::Kelvin. The implementation is:<br>
14
+ >> The initialization process retrieve temperature user input and specific Temperature Mode and store temperature in celsius form.<br>
15
+ >> [param] temperature: float --> the temperature value<br>
16
+ >> [param] mode: TemperatureMode --> the temperature unit (Fahrenheit, Celsius or Kelvin)<br>
17
+ >> Note the TemperatureMode is an enumerate that holds value of TemperatureMode::Celsius, TemperatureMode::Fahrenheit or TemperatureMode::Kelvin. The implementation is:<br>
18
18
 
19
19
  ```ruby
20
20
  module TemperatureMode
@@ -26,30 +26,30 @@ end
26
26
 
27
27
  **method**
28
28
 
29
- > ` def toFahrenheit() `
29
+ > def toFahrenheit()
30
30
 
31
- Convert the temperature to Fahrenheit<br>
32
- [return] temperature in Fahrenheit, type in float<br>
31
+ >> Convert the temperature to Fahrenheit<br>
32
+ >> [return] temperature in Fahrenheit, type in float<br>
33
33
 
34
- > ` def toKelvin() `
34
+ > def toKelvin()
35
35
 
36
- Convert the temperature to Kelvin<br>
37
- [return] temperature in Kelvin, type in float<br>
36
+ >> Convert the temperature to Kelvin<br>
37
+ >> [return] temperature in Kelvin, type in float<br>
38
38
 
39
39
  **Property**
40
40
 
41
- > ` this.temperature `
41
+ > attr_reader :temperature # default save in Celsius
42
42
 
43
- temperature in Celsius, type in float
43
+ >> temperature in Celsius, type in float
44
44
 
45
45
  ## Get Start
46
46
 
47
47
  Use following script for testing
48
48
 
49
49
  ```ruby
50
- temp = Temperature.new(-24, 1)
50
+ temp = Temperature.new(-24, 1) # construct 24 degree Celsius
51
51
 
52
- puts temp.toString
53
- puts "Current temperature is #{'%.2f' % temp.toFahrenheit} °F"
54
- puts "Current temperature is #{'%.2f' % temp.toKelvin} K"
52
+ puts temp.toString # the struct default save in Celsius
53
+ puts "Current temperature is #{'%.2f' % temp.toFahrenheit} °F" ## Convert to Fahrenheit
54
+ puts "Current temperature is #{'%.2f' % temp.toKelvin} K" ## Convert to Fahrenheit
55
55
  ```
@@ -10,38 +10,26 @@ module TemperatureMode
10
10
  Kelvin = 4
11
11
  end
12
12
 
13
-
13
+ # temperature class
14
14
  class Temperature
15
- # temperature class
16
15
 
16
+ # initial temperature (load & save in celsius form)
17
17
  def initialize(temperature, mode)
18
- # initial temperature (load & save in celsius form)
18
+ temp = temperature.to_f
19
19
 
20
20
  # first check the mode
21
21
  case mode
22
22
  when TemperatureMode::Celsius
23
- @temperature = temperature
23
+ @temperature = temp
24
24
  when TemperatureMode::Fahrenheit
25
- @temperature = Temperature.FahrenheitToCelsius(temperature)
25
+ @temperature = Temperature.FahrenheitToCelsius(temp)
26
26
  when TemperatureMode::Kelvin
27
- @temperature = Temperature.KelvinToCelsius(temperature)
27
+ @temperature = Temperature.KelvinToCelsius(temp)
28
28
  else
29
29
  # invalid mode met
30
30
  raise ArgumentError, "The temperature can only be chosen within fehrenheit, celsius and kelvin!"
31
31
  end
32
32
 
33
- # now use switch case rather than if else
34
- # if mode === TemperatureMode::Celsius
35
- # @temperature = temperature
36
- # elsif mode === TemperatureMode::Fahrenheit
37
- # @temperature = Temperature.FahrenheitToCelsius(temperature)
38
- # elsif mode === TemperatureMode::Kelvin
39
- # @temperature = Temperature.KelvinToCelsius(temperature)
40
- # else
41
- # # invalid mode met
42
- # raise ArgumentError, "The temperature can only be chosen within fehrenheit, celsius and kelvin!"
43
- # end
44
-
45
33
  end
46
34
 
47
35
  attr_reader :temperature
@@ -75,12 +63,3 @@ class Temperature
75
63
  end
76
64
 
77
65
  end
78
-
79
- if __FILE__ == $0
80
- temp = Temperature.new(-24, 1)
81
-
82
- puts temp.toString
83
- # puts temp.temperature
84
- puts "Current temperature is #{'%.2f' % temp.toFahrenheit} °F"
85
- puts "Current temperature is #{'%.2f' % temp.toKelvin} K"
86
- end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tempture-convertor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sicheng Zhong
@@ -9,62 +9,6 @@ bindir: bin
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies: []
12
- description: |-
13
- # Temperature Convertor
14
-
15
- convert temperature from fehrenheit or kelvin to celsius
16
-
17
-
18
- ## Detail
19
-
20
- The "Temperature" class stores and controls the value and convert function
21
-
22
- **Constructor**
23
-
24
- > ` def initialize(temperature, mode) `
25
-
26
- The initialization process retrieve temperature user input and specific Temperature Mode and store temperature in celsius form.<br>
27
- [param] temperature: float --> the temperature value<br>
28
- [param] mode: TemperatureMode --> the temperature unit (Fahrenheit, Celsius or Kelvin)<br>
29
- Note the TemperatureMode is an enumerate that holds value of TemperatureMode::Celsius, TemperatureMode::Fahrenheit or TemperatureMode::Kelvin. The implementation is:<br>
30
-
31
- ```ruby
32
- module TemperatureMode
33
- Celsius = 1
34
- Fahrenheit = 2
35
- Kelvin = 4
36
- end
37
- ```
38
-
39
- **method**
40
-
41
- > ` def toFahrenheit() `
42
-
43
- Convert the temperature to Fahrenheit<br>
44
- [return] temperature in Fahrenheit, type in float<br>
45
-
46
- > ` def toKelvin() `
47
-
48
- Convert the temperature to Kelvin<br>
49
- [return] temperature in Kelvin, type in float<br>
50
-
51
- **Property**
52
-
53
- > ` this.temperature `
54
-
55
- temperature in Celsius, type in float
56
-
57
- ## Get Start
58
-
59
- Use following script for testing
60
-
61
- ```ruby
62
- temp = Temperature.new(-24, 1)
63
-
64
- puts temp.toString
65
- puts "Current temperature is #{'%.2f' % temp.toFahrenheit} °F"
66
- puts "Current temperature is #{'%.2f' % temp.toKelvin} K"
67
- ```
68
12
  executables: []
69
13
  extensions: []
70
14
  extra_rdoc_files: []
@@ -73,7 +17,7 @@ files:
73
17
  - lib/tempture_convertor.rb
74
18
  homepage: https://github.com/Ayano-Keiko
75
19
  licenses:
76
- - GPL-3.0-only
20
+ - MIT
77
21
  metadata: {}
78
22
  rdoc_options: []
79
23
  require_paths:
@@ -89,7 +33,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
33
  - !ruby/object:Gem::Version
90
34
  version: '0'
91
35
  requirements: []
92
- rubygems_version: 4.0.3
36
+ rubygems_version: 4.0.21
93
37
  specification_version: 4
94
38
  summary: temperature converting between fehrenheit, kelvin and celsius
95
39
  test_files: []