tempura 0.0.1 → 0.1.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.
- data/README.md +66 -70
 - data/lib/tempura.rb +2 -0
 - data/lib/tempura/celsius.rb +11 -1
 - data/lib/tempura/conversion.rb +47 -0
 - data/lib/tempura/core_ext/numeric.rb +39 -0
 - data/lib/tempura/delisle.rb +11 -1
 - data/lib/tempura/fahrenheit.rb +11 -1
 - data/lib/tempura/kelvin.rb +11 -1
 - data/lib/tempura/newton.rb +11 -1
 - data/lib/tempura/rankine.rb +11 -1
 - data/lib/tempura/r/303/251aumur.rb +11 -1
 - data/lib/tempura/r/303/270mer.rb +11 -1
 - data/lib/tempura/temperature.rb +49 -117
 - data/lib/tempura/version.rb +1 -1
 - data/spec/spec_helper.rb +20 -20
 - data/spec/tempura/conversion_spec.rb +35 -0
 - data/spec/tempura/core_ext_spec.rb +58 -0
 - data/spec/tempura/temperature_spec.rb +3 -3
 - data/tempura.gemspec +4 -0
 - metadata +10 -4
 
    
        data/README.md
    CHANGED
    
    | 
         @@ -1,25 +1,31 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # Tempura
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
            Tempura is a library for temperature  
     | 
| 
      
 3 
     | 
    
         
            +
            Tempura is a library for temperature arithmetic, comparison, and conversion. Currently supported scales are Fahrenheit, Celsius, Kelvin, Delisle, Newton, Rankine, Réaumer, and Rømer.
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
      
 5 
     | 
    
         
            +
            Temperature objects may be instantiated directly, e.g. `Tempura::Celsius.new(100)`, or by using the methods defined on `Numeric`, e.g., `212.degrees_fahrenheit`
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
      
 7 
     | 
    
         
            +
            ## Usage
         
     | 
| 
       8 
8 
     | 
    
         | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
      
 9 
     | 
    
         
            +
            ### Instantiation
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
      
 11 
     | 
    
         
            +
            Direct instantiation:
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
      
 13 
     | 
    
         
            +
            		Tempura::Fahrenheit.new(212)
         
     | 
| 
       14 
14 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
      
 15 
     | 
    
         
            +
            Via Numeric:
         
     | 
| 
       16 
16 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
      
 17 
     | 
    
         
            +
            		100.degrees_celsius
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
      
 19 
     | 
    
         
            +
            ### Conversion
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
            `Tempura::Temperature` (each scales parent object) implements `#to`, which returns a `Tempura::Conversion`, which then may receive the name of a scale to convert to:
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
            		212.degrees_fahrenheit.to.celsius #=> <Tempura::Celsius...
         
     | 
| 
       20 
24 
     | 
    
         | 
| 
       21 
25 
     | 
    
         
             
            ### Arithmetic
         
     | 
| 
       22 
26 
     | 
    
         | 
| 
      
 27 
     | 
    
         
            +
            Subtract other temperatures of any scale, or native degrees:
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
       23 
29 
     | 
    
         
             
                it 'subtracts another temperature' do
         
     | 
| 
       24 
30 
     | 
    
         
             
                  fahrenheit = Tempura::Fahrenheit.new(212)
         
     | 
| 
       25 
31 
     | 
    
         
             
                  celsius = Tempura::Celsius.new(0)
         
     | 
| 
         @@ -35,6 +41,8 @@ Or install it yourself as: 
     | 
|
| 
       35 
41 
     | 
    
         
             
                  expect(result).to be_a(Tempura::Fahrenheit)
         
     | 
| 
       36 
42 
     | 
    
         
             
                end
         
     | 
| 
       37 
43 
     | 
    
         | 
| 
      
 44 
     | 
    
         
            +
            Add temperatures of any scale, or native degrees:
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
       38 
46 
     | 
    
         
             
                it 'adds another temperature' do
         
     | 
| 
       39 
47 
     | 
    
         
             
                  fahrenheit = Tempura::Fahrenheit.new(212)
         
     | 
| 
       40 
48 
     | 
    
         
             
                  celsius = Tempura::Celsius.new(0)
         
     | 
| 
         @@ -50,6 +58,8 @@ Or install it yourself as: 
     | 
|
| 
       50 
58 
     | 
    
         
             
                  expect(result).to be_a(Tempura::Fahrenheit)
         
     | 
| 
       51 
59 
     | 
    
         
             
                end
         
     | 
| 
       52 
60 
     | 
    
         | 
| 
      
 61 
     | 
    
         
            +
            Divide a temperature by a numeric:
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
       53 
63 
     | 
    
         
             
                it 'divides by a Numeric' do
         
     | 
| 
       54 
64 
     | 
    
         
             
                  fahrenheit = Tempura::Fahrenheit.new(212)
         
     | 
| 
       55 
65 
     | 
    
         
             
                  result = fahrenheit / 2
         
     | 
| 
         @@ -57,13 +67,6 @@ Or install it yourself as: 
     | 
|
| 
       57 
67 
     | 
    
         
             
                  expect(result).to be_a(Tempura::Fahrenheit)
         
     | 
| 
       58 
68 
     | 
    
         
             
                end
         
     | 
| 
       59 
69 
     | 
    
         | 
| 
       60 
     | 
    
         
            -
                it 'multiplies by a Numeric' do
         
     | 
| 
       61 
     | 
    
         
            -
                  fahrenheit = Tempura::Fahrenheit.new(212)
         
     | 
| 
       62 
     | 
    
         
            -
                  result = fahrenheit * 2
         
     | 
| 
       63 
     | 
    
         
            -
                  expect(result).to eq(424)
         
     | 
| 
       64 
     | 
    
         
            -
                  expect(result).to be_a(Tempura::Fahrenheit)
         
     | 
| 
       65 
     | 
    
         
            -
                end
         
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
       67 
70 
     | 
    
         
             
                it 'can average an array of temperatures' do
         
     | 
| 
       68 
71 
     | 
    
         
             
                  f = Tempura::Fahrenheit.new(212)
         
     | 
| 
       69 
72 
     | 
    
         
             
                  c = Tempura::Celsius.new(100)
         
     | 
| 
         @@ -74,68 +77,61 @@ Or install it yourself as: 
     | 
|
| 
       74 
77 
     | 
    
         
             
                  expect(result).to be_a(Tempura::Delisle)
         
     | 
| 
       75 
78 
     | 
    
         
             
                end
         
     | 
| 
       76 
79 
     | 
    
         | 
| 
      
 80 
     | 
    
         
            +
            Multiply a temperature by a numeric:
         
     | 
| 
      
 81 
     | 
    
         
            +
             
     | 
| 
      
 82 
     | 
    
         
            +
                it 'multiplies by a Numeric' do
         
     | 
| 
      
 83 
     | 
    
         
            +
                  fahrenheit = Tempura::Fahrenheit.new(212)
         
     | 
| 
      
 84 
     | 
    
         
            +
                  result = fahrenheit * 2
         
     | 
| 
      
 85 
     | 
    
         
            +
                  expect(result).to eq(424)
         
     | 
| 
      
 86 
     | 
    
         
            +
                  expect(result).to be_a(Tempura::Fahrenheit)
         
     | 
| 
      
 87 
     | 
    
         
            +
                end
         
     | 
| 
      
 88 
     | 
    
         
            +
             
     | 
| 
       77 
89 
     | 
    
         
             
            ### Comparison
         
     | 
| 
       78 
90 
     | 
    
         | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
       81 
     | 
    
         
            -
             
     | 
| 
       82 
     | 
    
         
            -
             
     | 
| 
       83 
     | 
    
         
            -
             
     | 
| 
       84 
     | 
    
         
            -
             
     | 
| 
       85 
     | 
    
         
            -
             
     | 
| 
       86 
     | 
    
         
            -
             
     | 
| 
       87 
     | 
    
         
            -
             
     | 
| 
       88 
     | 
    
         
            -
             
     | 
| 
       89 
     | 
    
         
            -
             
     | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
       91 
     | 
    
         
            -
             
     | 
| 
       92 
     | 
    
         
            -
             
     | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
       95 
     | 
    
         
            -
             
     | 
| 
       96 
     | 
    
         
            -
             
     | 
| 
       97 
     | 
    
         
            -
             
     | 
| 
       98 
     | 
    
         
            -
             
     | 
| 
       99 
     | 
    
         
            -
            			celsius = Tempura::Celsius.new(99)
         
     | 
| 
       100 
     | 
    
         
            -
            			expect(fahrenheit >= celsius).to be_true
         
     | 
| 
       101 
     | 
    
         
            -
            		end
         
     | 
| 
       102 
     | 
    
         
            -
             
     | 
| 
       103 
     | 
    
         
            -
            		it 'has ==' do
         
     | 
| 
       104 
     | 
    
         
            -
            			c = Tempura::Celsius.new(100)
         
     | 
| 
       105 
     | 
    
         
            -
            			d = Tempura::Delisle.new(0)
         
     | 
| 
       106 
     | 
    
         
            -
            			f = Tempura::Fahrenheit.new(212)
         
     | 
| 
       107 
     | 
    
         
            -
            			n = Tempura::Newton.new(33)
         
     | 
| 
       108 
     | 
    
         
            -
            			ra = Tempura::Rankine.new(671.67)
         
     | 
| 
       109 
     | 
    
         
            -
            			ré = Tempura::Réaumur.new(80)
         
     | 
| 
       110 
     | 
    
         
            -
            			rø = Tempura::Rømer.new(60)
         
     | 
| 
       111 
     | 
    
         
            -
             
     | 
| 
       112 
     | 
    
         
            -
            			scales = [c, d, f, n, ra, ré, rø]
         
     | 
| 
       113 
     | 
    
         
            -
            			scales.each { |s1|
         
     | 
| 
       114 
     | 
    
         
            -
            				scales.each { |s2|
         
     | 
| 
       115 
     | 
    
         
            -
            					expect(s1 == s2).to be_true
         
     | 
| 
       116 
     | 
    
         
            -
            				}
         
     | 
| 
      
 91 
     | 
    
         
            +
            `>`, `<`, `<=`, `>=`, `<=>`, and `==` are supported. Temperatures of the same or different scales may be compared, or a temperature may be compared with native degrees.
         
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
| 
      
 93 
     | 
    
         
            +
                Tempura::Fahrenheit.new(212) > Tempura::Celsius.new(99)
         
     | 
| 
      
 94 
     | 
    
         
            +
                Tempura::Fahrenheit.new(212) < Tempura::Celsius.new(101)
         
     | 
| 
      
 95 
     | 
    
         
            +
                Tempura::Fahrenheit.new(212) >= Tempura::Celsius.new(99)
         
     | 
| 
      
 96 
     | 
    
         
            +
                Tempura::Fahrenheit.new(212) <= Tempura::Celsius.new(101)
         
     | 
| 
      
 97 
     | 
    
         
            +
             
     | 
| 
      
 98 
     | 
    
         
            +
                scales = [
         
     | 
| 
      
 99 
     | 
    
         
            +
            		  Tempura::Celsius.new(100),
         
     | 
| 
      
 100 
     | 
    
         
            +
            		  Tempura::Delisle.new(0),
         
     | 
| 
      
 101 
     | 
    
         
            +
            		  Tempura::Fahrenheit.new(212),
         
     | 
| 
      
 102 
     | 
    
         
            +
            		  Tempura::Newton.new(33),
         
     | 
| 
      
 103 
     | 
    
         
            +
            		  Tempura::Rankine.new(671.67),
         
     | 
| 
      
 104 
     | 
    
         
            +
            		  Tempura::Réaumur.new(80),
         
     | 
| 
      
 105 
     | 
    
         
            +
            		  Tempura::Rømer.new(60),
         
     | 
| 
      
 106 
     | 
    
         
            +
            		]
         
     | 
| 
      
 107 
     | 
    
         
            +
             
     | 
| 
      
 108 
     | 
    
         
            +
            		scales.all? { |s1|
         
     | 
| 
      
 109 
     | 
    
         
            +
            			scales.each { |s2|
         
     | 
| 
      
 110 
     | 
    
         
            +
            		    s1 == s2
         
     | 
| 
       117 
111 
     | 
    
         
             
            			}
         
     | 
| 
       118 
     | 
    
         
            -
            		 
     | 
| 
      
 112 
     | 
    
         
            +
            		}
         
     | 
| 
      
 113 
     | 
    
         
            +
             
     | 
| 
      
 114 
     | 
    
         
            +
                #=> true
         
     | 
| 
       119 
115 
     | 
    
         | 
| 
       120 
116 
     | 
    
         
             
            ### Casting
         
     | 
| 
       121 
117 
     | 
    
         | 
| 
       122 
     | 
    
         
            -
                 
     | 
| 
       123 
     | 
    
         
            -
             
     | 
| 
       124 
     | 
    
         
            -
             
     | 
| 
       125 
     | 
    
         
            -
                  expect(temp.to_f).to be_a(Float)
         
     | 
| 
       126 
     | 
    
         
            -
                end
         
     | 
| 
      
 118 
     | 
    
         
            +
                Tempura::Fahrenheit.new(212).to_f
         
     | 
| 
      
 119 
     | 
    
         
            +
                Tempura::Kelvin.new(373.15).to_i
         
     | 
| 
      
 120 
     | 
    
         
            +
                Tempura::Celsius.new(100).to_d
         
     | 
| 
       127 
121 
     | 
    
         | 
| 
       128 
     | 
    
         
            -
             
     | 
| 
       129 
     | 
    
         
            -
                  temp = Tempura::Kelvin.new(373.15)
         
     | 
| 
       130 
     | 
    
         
            -
                  expect(temp.to_i).to eq(373)
         
     | 
| 
       131 
     | 
    
         
            -
                  expect(temp.to_i).to be_a(Integer)
         
     | 
| 
       132 
     | 
    
         
            -
                end
         
     | 
| 
      
 122 
     | 
    
         
            +
            ## Installation
         
     | 
| 
       133 
123 
     | 
    
         | 
| 
       134 
     | 
    
         
            -
             
     | 
| 
       135 
     | 
    
         
            -
             
     | 
| 
       136 
     | 
    
         
            -
             
     | 
| 
       137 
     | 
    
         
            -
             
     | 
| 
       138 
     | 
    
         
            -
             
     | 
| 
      
 124 
     | 
    
         
            +
            Add this line to your application's Gemfile:
         
     | 
| 
      
 125 
     | 
    
         
            +
             
     | 
| 
      
 126 
     | 
    
         
            +
                gem 'tempura'
         
     | 
| 
      
 127 
     | 
    
         
            +
             
     | 
| 
      
 128 
     | 
    
         
            +
            And then execute:
         
     | 
| 
      
 129 
     | 
    
         
            +
             
     | 
| 
      
 130 
     | 
    
         
            +
                $ bundle
         
     | 
| 
      
 131 
     | 
    
         
            +
             
     | 
| 
      
 132 
     | 
    
         
            +
            Or install it yourself as:
         
     | 
| 
      
 133 
     | 
    
         
            +
             
     | 
| 
      
 134 
     | 
    
         
            +
                $ gem install tempura
         
     | 
| 
       139 
135 
     | 
    
         | 
| 
       140 
136 
     | 
    
         
             
            ## Contributing
         
     | 
| 
       141 
137 
     | 
    
         | 
    
        data/lib/tempura.rb
    CHANGED
    
    
    
        data/lib/tempura/celsius.rb
    CHANGED
    
    
| 
         @@ -0,0 +1,47 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # encoding: utf-8
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            class Tempura::Conversion
         
     | 
| 
      
 4 
     | 
    
         
            +
              
         
     | 
| 
      
 5 
     | 
    
         
            +
              def initialize(klass)
         
     | 
| 
      
 6 
     | 
    
         
            +
                @klass = klass
         
     | 
| 
      
 7 
     | 
    
         
            +
              end
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
              def celsius
         
     | 
| 
      
 10 
     | 
    
         
            +
                Tempura::Celsius.new(klass)
         
     | 
| 
      
 11 
     | 
    
         
            +
              end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
              def delisle
         
     | 
| 
      
 14 
     | 
    
         
            +
                Tempura::Delisle.new(klass)
         
     | 
| 
      
 15 
     | 
    
         
            +
              end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
              def fahrenheit
         
     | 
| 
      
 18 
     | 
    
         
            +
                Tempura::Fahrenheit.new(klass)
         
     | 
| 
      
 19 
     | 
    
         
            +
              end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
              def kelvin
         
     | 
| 
      
 22 
     | 
    
         
            +
                Tempura::Kelvin.new(klass)
         
     | 
| 
      
 23 
     | 
    
         
            +
              end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
              def newton
         
     | 
| 
      
 26 
     | 
    
         
            +
                Tempura::Newton.new(klass)
         
     | 
| 
      
 27 
     | 
    
         
            +
              end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
              def rankine
         
     | 
| 
      
 30 
     | 
    
         
            +
                Tempura::Rankine.new(klass)
         
     | 
| 
      
 31 
     | 
    
         
            +
              end
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
              def réaumur
         
     | 
| 
      
 34 
     | 
    
         
            +
                Tempura::Réaumur.new(klass)
         
     | 
| 
      
 35 
     | 
    
         
            +
              end
         
     | 
| 
      
 36 
     | 
    
         
            +
              alias :reaumur :réaumur
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
              def rømer
         
     | 
| 
      
 39 
     | 
    
         
            +
                Tempura::Rømer.new(klass)
         
     | 
| 
      
 40 
     | 
    
         
            +
              end
         
     | 
| 
      
 41 
     | 
    
         
            +
              alias :romer :rømer
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
              private
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
              attr_reader :klass
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,39 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # encoding: utf-8
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            class Numeric
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
              def degrees_celsius
         
     | 
| 
      
 6 
     | 
    
         
            +
                Tempura::Celsius.new(self)
         
     | 
| 
      
 7 
     | 
    
         
            +
              end
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
              def degrees_delisle
         
     | 
| 
      
 10 
     | 
    
         
            +
                Tempura::Delisle.new(self)
         
     | 
| 
      
 11 
     | 
    
         
            +
              end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
              def degrees_fahrenheit
         
     | 
| 
      
 14 
     | 
    
         
            +
                Tempura::Fahrenheit.new(self)
         
     | 
| 
      
 15 
     | 
    
         
            +
              end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
              def degrees_kelvin
         
     | 
| 
      
 18 
     | 
    
         
            +
                Tempura::Kelvin.new(self)
         
     | 
| 
      
 19 
     | 
    
         
            +
              end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
              def degrees_newton
         
     | 
| 
      
 22 
     | 
    
         
            +
                Tempura::Newton.new(self)
         
     | 
| 
      
 23 
     | 
    
         
            +
              end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
              def degrees_rankine
         
     | 
| 
      
 26 
     | 
    
         
            +
                Tempura::Rankine.new(self)
         
     | 
| 
      
 27 
     | 
    
         
            +
              end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
              def degrees_réaumur
         
     | 
| 
      
 30 
     | 
    
         
            +
                Tempura::Réaumur.new(self)
         
     | 
| 
      
 31 
     | 
    
         
            +
              end
         
     | 
| 
      
 32 
     | 
    
         
            +
              alias :degrees_reaumur :degrees_réaumur
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
              def degrees_rømer
         
     | 
| 
      
 35 
     | 
    
         
            +
                Tempura::Rømer.new(self)
         
     | 
| 
      
 36 
     | 
    
         
            +
              end
         
     | 
| 
      
 37 
     | 
    
         
            +
              alias :degrees_romer :degrees_rømer
         
     | 
| 
      
 38 
     | 
    
         
            +
              
         
     | 
| 
      
 39 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/tempura/delisle.rb
    CHANGED
    
    
    
        data/lib/tempura/fahrenheit.rb
    CHANGED
    
    | 
         @@ -1 +1,11 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            class Tempura::Fahrenheit < Tempura::Temperature 
     | 
| 
      
 1 
     | 
    
         
            +
            class Tempura::Fahrenheit < Tempura::Temperature
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
              def from_native(given)
         
     | 
| 
      
 4 
     | 
    
         
            +
                ((given + BigDecimal("459.67")) * 5) / 9
         
     | 
| 
      
 5 
     | 
    
         
            +
              end
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
              def self.as_native(k)
         
     | 
| 
      
 8 
     | 
    
         
            +
                ((k * 9)/5) - BigDecimal("459.67")
         
     | 
| 
      
 9 
     | 
    
         
            +
              end
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/tempura/kelvin.rb
    CHANGED
    
    
    
        data/lib/tempura/newton.rb
    CHANGED
    
    
    
        data/lib/tempura/rankine.rb
    CHANGED
    
    
| 
         @@ -1,2 +1,12 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # encoding: utf-8
         
     | 
| 
       2 
     | 
    
         
            -
            class Tempura::Réaumur < Tempura::Temperature 
     | 
| 
      
 2 
     | 
    
         
            +
            class Tempura::Réaumur < Tempura::Temperature
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
              def from_native(given)
         
     | 
| 
      
 5 
     | 
    
         
            +
                ((given * 5) / 4) + BigDecimal("273.15")
         
     | 
| 
      
 6 
     | 
    
         
            +
              end
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
              def self.as_native(k)
         
     | 
| 
      
 9 
     | 
    
         
            +
                ((k - BigDecimal("273.15")) * 4) / 5
         
     | 
| 
      
 10 
     | 
    
         
            +
              end
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/tempura/r/303/270mer.rb
    CHANGED
    
    | 
         @@ -1,2 +1,12 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # encoding: utf-8
         
     | 
| 
       2 
     | 
    
         
            -
            class Tempura::Rømer < Tempura::Temperature 
     | 
| 
      
 2 
     | 
    
         
            +
            class Tempura::Rømer < Tempura::Temperature
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
              def from_native(given)
         
     | 
| 
      
 5 
     | 
    
         
            +
                (((given - BigDecimal("7.5")) * 40) / 21) + BigDecimal("273.15")
         
     | 
| 
      
 6 
     | 
    
         
            +
              end
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
              def self.as_native(k)
         
     | 
| 
      
 9 
     | 
    
         
            +
                (((k - BigDecimal("273.15")) * 21) / 40) + BigDecimal("7.5")
         
     | 
| 
      
 10 
     | 
    
         
            +
              end
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/tempura/temperature.rb
    CHANGED
    
    | 
         @@ -1,14 +1,20 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # encoding: utf-8
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
      
 3 
     | 
    
         
            +
            # Parent class of all +Temperature+ objects in +Tempura+, inherited by +Tempura::Celsius+, etc.
         
     | 
| 
       5 
4 
     | 
    
         
             
            class Tempura::Temperature
         
     | 
| 
       6 
5 
     | 
    
         
             
              include Comparable
         
     | 
| 
       7 
6 
     | 
    
         | 
| 
       8 
     | 
    
         
            -
              def initialize( 
     | 
| 
       9 
     | 
    
         
            -
                 
     | 
| 
      
 7 
     | 
    
         
            +
              def initialize(temp)
         
     | 
| 
      
 8 
     | 
    
         
            +
                if temp.is_a?(Tempura::Temperature)
         
     | 
| 
      
 9 
     | 
    
         
            +
                  @common = temp.send(:common)
         
     | 
| 
      
 10 
     | 
    
         
            +
                else
         
     | 
| 
      
 11 
     | 
    
         
            +
                  @common = to_common(temp)
         
     | 
| 
      
 12 
     | 
    
         
            +
                end
         
     | 
| 
       10 
13 
     | 
    
         
             
              end
         
     | 
| 
       11 
14 
     | 
    
         | 
| 
      
 15 
     | 
    
         
            +
              # Compares against a +Temperature+ of any scale, or a numeric representation of the same scale as the receiver.
         
     | 
| 
      
 16 
     | 
    
         
            +
              #
         
     | 
| 
      
 17 
     | 
    
         
            +
              # @param temp [Tempura::Temperature, Numeric]
         
     | 
| 
       12 
18 
     | 
    
         
             
              def <=>(temp)
         
     | 
| 
       13 
19 
     | 
    
         
             
                if temp.is_a?(Tempura::Temperature)
         
     | 
| 
       14 
20 
     | 
    
         
             
                  @common <=> temp.send(:common)
         
     | 
| 
         @@ -17,20 +23,23 @@ class Tempura::Temperature 
     | 
|
| 
       17 
23 
     | 
    
         
             
                end
         
     | 
| 
       18 
24 
     | 
    
         
             
              end
         
     | 
| 
       19 
25 
     | 
    
         | 
| 
      
 26 
     | 
    
         
            +
              # Subtracts a +Temperature+ of any scale, or a numeric representation of the same scale as the receiver.
         
     | 
| 
      
 27 
     | 
    
         
            +
              #
         
     | 
| 
      
 28 
     | 
    
         
            +
              # @param temp [Tempura::Temperature, Numeric]
         
     | 
| 
       20 
29 
     | 
    
         
             
              def -(temp)
         
     | 
| 
       21 
     | 
    
         
            -
                 
     | 
| 
       22 
     | 
    
         
            -
                  temp = to_native(temp)
         
     | 
| 
       23 
     | 
    
         
            -
                end
         
     | 
| 
       24 
     | 
    
         
            -
                self.class.new(in_native - temp)
         
     | 
| 
      
 30 
     | 
    
         
            +
                self.class.new(in_native - numericalize(temp))
         
     | 
| 
       25 
31 
     | 
    
         
             
              end
         
     | 
| 
       26 
32 
     | 
    
         | 
| 
      
 33 
     | 
    
         
            +
              # Adds a +Temperature+ of any scale, or a numeric representation of the same scale as the receiver.
         
     | 
| 
      
 34 
     | 
    
         
            +
              #
         
     | 
| 
      
 35 
     | 
    
         
            +
              # @param temp [Tempura::Temperature, Numeric]
         
     | 
| 
       27 
36 
     | 
    
         
             
              def +(temp)
         
     | 
| 
       28 
     | 
    
         
            -
                 
     | 
| 
       29 
     | 
    
         
            -
                  temp = to_native(temp)
         
     | 
| 
       30 
     | 
    
         
            -
                end
         
     | 
| 
       31 
     | 
    
         
            -
                self.class.new(in_native + temp)
         
     | 
| 
      
 37 
     | 
    
         
            +
                self.class.new(in_native + numericalize(temp))
         
     | 
| 
       32 
38 
     | 
    
         
             
              end
         
     | 
| 
       33 
39 
     | 
    
         | 
| 
      
 40 
     | 
    
         
            +
              # Divides by +Numeric+.
         
     | 
| 
      
 41 
     | 
    
         
            +
              #
         
     | 
| 
      
 42 
     | 
    
         
            +
              # @param temp [Numeric]
         
     | 
| 
       34 
43 
     | 
    
         
             
              def /(temp)
         
     | 
| 
       35 
44 
     | 
    
         
             
                if temp.is_a?(Tempura::Temperature)
         
     | 
| 
       36 
45 
     | 
    
         
             
                  raise ArgumentError, "cannot divide by a Tempura::Temperature, only a Numeric"
         
     | 
| 
         @@ -38,6 +47,9 @@ class Tempura::Temperature 
     | 
|
| 
       38 
47 
     | 
    
         
             
                self.class.new(in_native.div(temp))
         
     | 
| 
       39 
48 
     | 
    
         
             
              end
         
     | 
| 
       40 
49 
     | 
    
         | 
| 
      
 50 
     | 
    
         
            +
              # Multiplies by +Numeric+.
         
     | 
| 
      
 51 
     | 
    
         
            +
              #
         
     | 
| 
      
 52 
     | 
    
         
            +
              # @param temp [Numeric]
         
     | 
| 
       41 
53 
     | 
    
         
             
              def *(temp)
         
     | 
| 
       42 
54 
     | 
    
         
             
                if temp.is_a?(Tempura::Temperature)
         
     | 
| 
       43 
55 
     | 
    
         
             
                  raise ArgumentError, "cannot multiply by a Tempura::Temperature, only a Numeric"
         
     | 
| 
         @@ -45,131 +57,51 @@ class Tempura::Temperature 
     | 
|
| 
       45 
57 
     | 
    
         
             
                self.class.new(in_native * temp)
         
     | 
| 
       46 
58 
     | 
    
         
             
              end
         
     | 
| 
       47 
59 
     | 
    
         | 
| 
      
 60 
     | 
    
         
            +
              # Returns {Tempura::Conversion} for the receiver, which recieves the name of the scale to convert to. E.g.,
         
     | 
| 
      
 61 
     | 
    
         
            +
              #
         
     | 
| 
      
 62 
     | 
    
         
            +
              #     c = Tempura::Celsius.new(100)
         
     | 
| 
      
 63 
     | 
    
         
            +
              #     c.to.fahrenheit #=> <Tempura::Fahrenheit ...
         
     | 
| 
      
 64 
     | 
    
         
            +
              # 
         
     | 
| 
      
 65 
     | 
    
         
            +
              def to
         
     | 
| 
      
 66 
     | 
    
         
            +
                Tempura::Conversion.new(self)
         
     | 
| 
      
 67 
     | 
    
         
            +
              end
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
              # Float representation of receiver
         
     | 
| 
       48 
70 
     | 
    
         
             
              def to_f
         
     | 
| 
       49 
71 
     | 
    
         
             
                in_native.to_f
         
     | 
| 
       50 
72 
     | 
    
         
             
              end
         
     | 
| 
       51 
73 
     | 
    
         | 
| 
      
 74 
     | 
    
         
            +
              # Integer representation of receiver
         
     | 
| 
       52 
75 
     | 
    
         
             
              def to_i
         
     | 
| 
       53 
76 
     | 
    
         
             
                in_native.to_i
         
     | 
| 
       54 
77 
     | 
    
         
             
              end
         
     | 
| 
       55 
78 
     | 
    
         | 
| 
      
 79 
     | 
    
         
            +
              # BigDecimal representation of receiver
         
     | 
| 
       56 
80 
     | 
    
         
             
              def to_d
         
     | 
| 
       57 
81 
     | 
    
         
             
                in_native
         
     | 
| 
       58 
82 
     | 
    
         
             
              end
         
     | 
| 
       59 
83 
     | 
    
         | 
| 
       60 
     | 
    
         
            -
              def to_native(temp)
         
     | 
| 
       61 
     | 
    
         
            -
                temp.send("in_#{self.class.name.split('::').last.downcase}")
         
     | 
| 
       62 
     | 
    
         
            -
              end
         
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
              def from_celsius(given)
         
     | 
| 
       65 
     | 
    
         
            -
                given + BigDecimal("273.15")
         
     | 
| 
       66 
     | 
    
         
            -
              end
         
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
              def in_celsius
         
     | 
| 
       69 
     | 
    
         
            -
                common - BigDecimal("273.15")
         
     | 
| 
       70 
     | 
    
         
            -
              end
         
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
              def to_celsius
         
     | 
| 
       73 
     | 
    
         
            -
                Tempura::Celsius.new(in_celsius)
         
     | 
| 
       74 
     | 
    
         
            -
              end
         
     | 
| 
       75 
     | 
    
         
            -
             
     | 
| 
       76 
     | 
    
         
            -
              def from_delisle(given)
         
     | 
| 
       77 
     | 
    
         
            -
                BigDecimal("373.15") - ((given * 2) / 3)
         
     | 
| 
       78 
     | 
    
         
            -
              end
         
     | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
       80 
     | 
    
         
            -
              def in_delisle
         
     | 
| 
       81 
     | 
    
         
            -
                ((BigDecimal("373.15") - common) * 3) / 2
         
     | 
| 
       82 
     | 
    
         
            -
              end
         
     | 
| 
       83 
     | 
    
         
            -
             
     | 
| 
       84 
     | 
    
         
            -
              def to_delisle
         
     | 
| 
       85 
     | 
    
         
            -
                Tempura::Delisle.new(in_delisle)
         
     | 
| 
       86 
     | 
    
         
            -
              end
         
     | 
| 
       87 
     | 
    
         
            -
             
     | 
| 
       88 
     | 
    
         
            -
              def from_fahrenheit(given)
         
     | 
| 
       89 
     | 
    
         
            -
                ((given + BigDecimal("459.67")) * 5) / 9
         
     | 
| 
       90 
     | 
    
         
            -
              end
         
     | 
| 
       91 
     | 
    
         
            -
             
     | 
| 
       92 
     | 
    
         
            -
              def in_fahrenheit
         
     | 
| 
       93 
     | 
    
         
            -
                ((common * 9)/5) - BigDecimal("459.67")
         
     | 
| 
       94 
     | 
    
         
            -
              end
         
     | 
| 
       95 
     | 
    
         
            -
             
     | 
| 
       96 
     | 
    
         
            -
              def to_fahrenheit
         
     | 
| 
       97 
     | 
    
         
            -
                Tempura::Fahrenheit.new(in_fahrenheit)
         
     | 
| 
       98 
     | 
    
         
            -
              end
         
     | 
| 
       99 
     | 
    
         
            -
             
     | 
| 
       100 
     | 
    
         
            -
              def from_kelvin(given)
         
     | 
| 
       101 
     | 
    
         
            -
                given
         
     | 
| 
       102 
     | 
    
         
            -
              end
         
     | 
| 
       103 
     | 
    
         
            -
             
     | 
| 
       104 
     | 
    
         
            -
              def in_kelvin
         
     | 
| 
       105 
     | 
    
         
            -
                common
         
     | 
| 
       106 
     | 
    
         
            -
              end
         
     | 
| 
       107 
     | 
    
         
            -
              
         
     | 
| 
       108 
     | 
    
         
            -
              def to_kelvin
         
     | 
| 
       109 
     | 
    
         
            -
                Tempura::Kelvin.new(in_kelvin)
         
     | 
| 
       110 
     | 
    
         
            -
              end
         
     | 
| 
       111 
     | 
    
         
            -
             
     | 
| 
       112 
     | 
    
         
            -
              def from_newton(given)
         
     | 
| 
       113 
     | 
    
         
            -
                ((given * 100) / 33) + BigDecimal("273.15")
         
     | 
| 
       114 
     | 
    
         
            -
              end
         
     | 
| 
       115 
     | 
    
         
            -
             
     | 
| 
       116 
     | 
    
         
            -
              def in_newton
         
     | 
| 
       117 
     | 
    
         
            -
                ((common - BigDecimal("273.15")) * 33) / 100
         
     | 
| 
       118 
     | 
    
         
            -
              end
         
     | 
| 
       119 
     | 
    
         
            -
             
     | 
| 
       120 
     | 
    
         
            -
              def to_newton
         
     | 
| 
       121 
     | 
    
         
            -
                Tempura::Newton.new(in_newton)
         
     | 
| 
       122 
     | 
    
         
            -
              end
         
     | 
| 
       123 
     | 
    
         
            -
             
     | 
| 
       124 
     | 
    
         
            -
              def from_rankine(given)
         
     | 
| 
       125 
     | 
    
         
            -
                (given * 5) / 9
         
     | 
| 
       126 
     | 
    
         
            -
              end
         
     | 
| 
       127 
     | 
    
         
            -
             
     | 
| 
       128 
     | 
    
         
            -
              def in_rankine
         
     | 
| 
       129 
     | 
    
         
            -
                (common * 9) / 5
         
     | 
| 
       130 
     | 
    
         
            -
              end
         
     | 
| 
       131 
     | 
    
         
            -
             
     | 
| 
       132 
     | 
    
         
            -
              def to_rankine
         
     | 
| 
       133 
     | 
    
         
            -
                Tempura::Rankine.new(in_rankine)
         
     | 
| 
       134 
     | 
    
         
            -
              end
         
     | 
| 
       135 
     | 
    
         
            -
             
     | 
| 
       136 
     | 
    
         
            -
              def from_réaumur(given)
         
     | 
| 
       137 
     | 
    
         
            -
                ((given * 5) / 4) + BigDecimal("273.15")
         
     | 
| 
       138 
     | 
    
         
            -
              end
         
     | 
| 
       139 
     | 
    
         
            -
             
     | 
| 
       140 
     | 
    
         
            -
              def in_réaumur
         
     | 
| 
       141 
     | 
    
         
            -
                ((common - BigDecimal("273.15")) * 4) / 5
         
     | 
| 
       142 
     | 
    
         
            -
              end
         
     | 
| 
       143 
     | 
    
         
            -
              alias :in_reaumur :in_réaumur
         
     | 
| 
       144 
     | 
    
         
            -
             
     | 
| 
       145 
     | 
    
         
            -
              def to_réaumur
         
     | 
| 
       146 
     | 
    
         
            -
                Tempura::Réaumur.new(in_réaumur)
         
     | 
| 
       147 
     | 
    
         
            -
              end
         
     | 
| 
       148 
     | 
    
         
            -
              alias :to_reaumur :to_réaumur
         
     | 
| 
       149 
     | 
    
         
            -
             
     | 
| 
       150 
     | 
    
         
            -
              def from_rømer(given)
         
     | 
| 
       151 
     | 
    
         
            -
                (((given - BigDecimal("7.5")) * 40) / 21) + BigDecimal("273.15")
         
     | 
| 
       152 
     | 
    
         
            -
              end
         
     | 
| 
       153 
     | 
    
         
            -
             
     | 
| 
       154 
     | 
    
         
            -
              def in_rømer
         
     | 
| 
       155 
     | 
    
         
            -
                (((common - BigDecimal("273.15")) * 21) / 40) + BigDecimal("7.5")
         
     | 
| 
       156 
     | 
    
         
            -
              end
         
     | 
| 
       157 
     | 
    
         
            -
              alias :in_romer :in_rømer
         
     | 
| 
       158 
     | 
    
         
            -
             
     | 
| 
       159 
     | 
    
         
            -
              def to_rømer
         
     | 
| 
       160 
     | 
    
         
            -
                Tempura::Rømer.new(in_rømer)
         
     | 
| 
       161 
     | 
    
         
            -
              end
         
     | 
| 
       162 
     | 
    
         
            -
              alias :to_romer :to_rømer
         
     | 
| 
       163 
     | 
    
         
            -
             
     | 
| 
       164 
84 
     | 
    
         
             
              private
         
     | 
| 
       165 
85 
     | 
    
         | 
| 
       166 
86 
     | 
    
         
             
              attr_reader :common
         
     | 
| 
       167 
87 
     | 
    
         | 
| 
       168 
88 
     | 
    
         
             
              def to_common(given)
         
     | 
| 
       169 
     | 
    
         
            -
                self. 
     | 
| 
      
 89 
     | 
    
         
            +
                self.from_native(BigDecimal(given.to_s))
         
     | 
| 
       170 
90 
     | 
    
         
             
              end
         
     | 
| 
       171 
91 
     | 
    
         | 
| 
       172 
92 
     | 
    
         
             
              def in_native
         
     | 
| 
       173 
93 
     | 
    
         
             
                to_native(self)
         
     | 
| 
       174 
94 
     | 
    
         
             
              end
         
     | 
| 
      
 95 
     | 
    
         
            +
             
     | 
| 
      
 96 
     | 
    
         
            +
              def to_native(temp)
         
     | 
| 
      
 97 
     | 
    
         
            +
                self.class.as_native(temp.send(:common))
         
     | 
| 
      
 98 
     | 
    
         
            +
              end
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
      
 100 
     | 
    
         
            +
              def numericalize(temp)
         
     | 
| 
      
 101 
     | 
    
         
            +
                if temp.is_a?(Tempura::Temperature)
         
     | 
| 
      
 102 
     | 
    
         
            +
                  to_native(temp)
         
     | 
| 
      
 103 
     | 
    
         
            +
                else
         
     | 
| 
      
 104 
     | 
    
         
            +
                  temp
         
     | 
| 
      
 105 
     | 
    
         
            +
                end
         
     | 
| 
      
 106 
     | 
    
         
            +
              end
         
     | 
| 
       175 
107 
     | 
    
         
             
            end
         
     | 
    
        data/lib/tempura/version.rb
    CHANGED
    
    
    
        data/spec/spec_helper.rb
    CHANGED
    
    | 
         @@ -4,46 +4,46 @@ require 'tempura' 
     | 
|
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
            shared_examples_for '373.15 K' do
         
     | 
| 
       6 
6 
     | 
    
         
             
              it 'is expressable in Celsius (C)' do
         
     | 
| 
       7 
     | 
    
         
            -
                expect(subject. 
     | 
| 
       8 
     | 
    
         
            -
                expect(subject. 
     | 
| 
      
 7 
     | 
    
         
            +
                expect(subject.to.celsius).to eq(100)
         
     | 
| 
      
 8 
     | 
    
         
            +
                expect(subject.to.celsius).to be_a(Tempura::Celsius)
         
     | 
| 
       9 
9 
     | 
    
         
             
              end
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
11 
     | 
    
         
             
              it 'is expressable in Delisle (De)' do
         
     | 
| 
       12 
     | 
    
         
            -
                expect(subject. 
     | 
| 
       13 
     | 
    
         
            -
                expect(subject. 
     | 
| 
      
 12 
     | 
    
         
            +
                expect(subject.to.delisle).to eq(0)
         
     | 
| 
      
 13 
     | 
    
         
            +
                expect(subject.to.delisle).to be_a(Tempura::Delisle)
         
     | 
| 
       14 
14 
     | 
    
         
             
              end
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
16 
     | 
    
         
             
              it 'is expressable in Fahrenheit (F)' do
         
     | 
| 
       17 
     | 
    
         
            -
                expect(subject. 
     | 
| 
       18 
     | 
    
         
            -
                expect(subject. 
     | 
| 
      
 17 
     | 
    
         
            +
                expect(subject.to.fahrenheit).to eq(212)
         
     | 
| 
      
 18 
     | 
    
         
            +
                expect(subject.to.fahrenheit).to be_a(Tempura::Fahrenheit)
         
     | 
| 
       19 
19 
     | 
    
         
             
              end
         
     | 
| 
       20 
20 
     | 
    
         | 
| 
       21 
21 
     | 
    
         
             
              it 'is expressable in Kelvin (K)' do
         
     | 
| 
       22 
     | 
    
         
            -
                expect(subject. 
     | 
| 
       23 
     | 
    
         
            -
                expect(subject. 
     | 
| 
      
 22 
     | 
    
         
            +
                expect(subject.to.kelvin).to eq(373.15)
         
     | 
| 
      
 23 
     | 
    
         
            +
                expect(subject.to.kelvin).to be_a(Tempura::Kelvin)
         
     | 
| 
       24 
24 
     | 
    
         
             
              end
         
     | 
| 
       25 
25 
     | 
    
         | 
| 
       26 
26 
     | 
    
         
             
              it 'is expressable in Newton (N)' do
         
     | 
| 
       27 
     | 
    
         
            -
                expect(subject. 
     | 
| 
       28 
     | 
    
         
            -
                expect(subject. 
     | 
| 
      
 27 
     | 
    
         
            +
                expect(subject.to.newton).to eq(33)
         
     | 
| 
      
 28 
     | 
    
         
            +
                expect(subject.to.newton).to be_a(Tempura::Newton)
         
     | 
| 
       29 
29 
     | 
    
         
             
              end
         
     | 
| 
       30 
30 
     | 
    
         | 
| 
       31 
31 
     | 
    
         
             
              it 'is expressable in Rankine (R)' do
         
     | 
| 
       32 
     | 
    
         
            -
                expect(subject. 
     | 
| 
       33 
     | 
    
         
            -
                expect(subject. 
     | 
| 
      
 32 
     | 
    
         
            +
                expect(subject.to.rankine).to eq(671.67)
         
     | 
| 
      
 33 
     | 
    
         
            +
                expect(subject.to.rankine).to be_a(Tempura::Rankine)
         
     | 
| 
       34 
34 
     | 
    
         
             
              end
         
     | 
| 
       35 
35 
     | 
    
         | 
| 
       36 
36 
     | 
    
         
             
              it 'is expressable in Réaumur (Ré)' do
         
     | 
| 
       37 
     | 
    
         
            -
                expect(subject. 
     | 
| 
       38 
     | 
    
         
            -
                expect(subject. 
     | 
| 
       39 
     | 
    
         
            -
                expect(subject. 
     | 
| 
       40 
     | 
    
         
            -
                expect(subject. 
     | 
| 
      
 37 
     | 
    
         
            +
                expect(subject.to.réaumur).to eq(80)
         
     | 
| 
      
 38 
     | 
    
         
            +
                expect(subject.to.réaumur).to be_a(Tempura::Réaumur)
         
     | 
| 
      
 39 
     | 
    
         
            +
                expect(subject.to.reaumur).to eq(80)
         
     | 
| 
      
 40 
     | 
    
         
            +
                expect(subject.to.reaumur).to be_a(Tempura::Réaumur)
         
     | 
| 
       41 
41 
     | 
    
         
             
              end
         
     | 
| 
       42 
42 
     | 
    
         | 
| 
       43 
43 
     | 
    
         
             
              it 'is expressable in Rømer (Rø)' do
         
     | 
| 
       44 
     | 
    
         
            -
                expect(subject. 
     | 
| 
       45 
     | 
    
         
            -
                expect(subject. 
     | 
| 
       46 
     | 
    
         
            -
                expect(subject. 
     | 
| 
       47 
     | 
    
         
            -
                expect(subject. 
     | 
| 
      
 44 
     | 
    
         
            +
                expect(subject.to.rømer).to eq(60)
         
     | 
| 
      
 45 
     | 
    
         
            +
                expect(subject.to.rømer).to be_a(Tempura::Rømer)
         
     | 
| 
      
 46 
     | 
    
         
            +
                expect(subject.to.romer).to eq(60)
         
     | 
| 
      
 47 
     | 
    
         
            +
                expect(subject.to.rømer).to be_a(Tempura::Rømer)
         
     | 
| 
       48 
48 
     | 
    
         
             
              end
         
     | 
| 
       49 
49 
     | 
    
         
             
            end
         
     | 
| 
         @@ -0,0 +1,35 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # encoding: utf-8
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            describe Tempura::Conversion do
         
     | 
| 
      
 6 
     | 
    
         
            +
              let(:c) { 100.degrees_celsius }
         
     | 
| 
      
 7 
     | 
    
         
            +
              let(:d) { 0.degrees_delisle }
         
     | 
| 
      
 8 
     | 
    
         
            +
              let(:f) { 212.degrees_fahrenheit }
         
     | 
| 
      
 9 
     | 
    
         
            +
              let(:n) { 33.degrees_newton }
         
     | 
| 
      
 10 
     | 
    
         
            +
              let(:ra) { 671.67.degrees_rankine }
         
     | 
| 
      
 11 
     | 
    
         
            +
              let(:ré) { 80.degrees_réaumur }
         
     | 
| 
      
 12 
     | 
    
         
            +
              let(:rø) { 60.degrees_rømer }
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
              it 'provides a common interface' do
         
     | 
| 
      
 15 
     | 
    
         
            +
                [c, d, f, n, ra, ré, rø].each do |t|
         
     | 
| 
      
 16 
     | 
    
         
            +
                  expect(t.to).to be_a(Tempura::Conversion)
         
     | 
| 
      
 17 
     | 
    
         
            +
                end
         
     | 
| 
      
 18 
     | 
    
         
            +
              end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
              describe 'converting to temps' do
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                it 'converts to a scale' do
         
     | 
| 
      
 23 
     | 
    
         
            +
                  c2f = c.to.fahrenheit
         
     | 
| 
      
 24 
     | 
    
         
            +
                  expect(c2f).to be_a(Tempura::Fahrenheit)
         
     | 
| 
      
 25 
     | 
    
         
            +
                  expect(c2f).to eq(f)
         
     | 
| 
      
 26 
     | 
    
         
            +
                end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                it 'converts to an aliased scale' do
         
     | 
| 
      
 29 
     | 
    
         
            +
                  n2ro = n.to.romer
         
     | 
| 
      
 30 
     | 
    
         
            +
                  expect(n2ro).to be_a(Tempura::Rømer)
         
     | 
| 
      
 31 
     | 
    
         
            +
                  expect(n2ro).to eq(rø)
         
     | 
| 
      
 32 
     | 
    
         
            +
                end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
              end
         
     | 
| 
      
 35 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,58 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # encoding: utf-8
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            describe Numeric do
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
              describe 'converting to temps' do
         
     | 
| 
      
 8 
     | 
    
         
            +
                let(:c) { 100.degrees_celsius }
         
     | 
| 
      
 9 
     | 
    
         
            +
                let(:d) { 0.degrees_delisle }
         
     | 
| 
      
 10 
     | 
    
         
            +
                let(:f) { 212.degrees_fahrenheit }
         
     | 
| 
      
 11 
     | 
    
         
            +
                let(:n) { 33.degrees_newton }
         
     | 
| 
      
 12 
     | 
    
         
            +
                let(:ra) { 671.67.degrees_rankine }
         
     | 
| 
      
 13 
     | 
    
         
            +
                let(:ré) { 80.degrees_réaumur }
         
     | 
| 
      
 14 
     | 
    
         
            +
                let(:re) { 80.degrees_reaumur }
         
     | 
| 
      
 15 
     | 
    
         
            +
                let(:rø) { 60.degrees_rømer }
         
     | 
| 
      
 16 
     | 
    
         
            +
                let(:ro) { 60.degrees_romer }
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                it 'converts to celsius' do
         
     | 
| 
      
 19 
     | 
    
         
            +
                  expect(c).to be_a(Tempura::Celsius)
         
     | 
| 
      
 20 
     | 
    
         
            +
                end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                it 'converts to delisle' do
         
     | 
| 
      
 23 
     | 
    
         
            +
                  expect(d).to be_a(Tempura::Delisle)
         
     | 
| 
      
 24 
     | 
    
         
            +
                end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                it 'converts to fahrenheit' do
         
     | 
| 
      
 27 
     | 
    
         
            +
                  expect(f).to be_a(Tempura::Fahrenheit)
         
     | 
| 
      
 28 
     | 
    
         
            +
                end
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                it 'converts to newton' do
         
     | 
| 
      
 31 
     | 
    
         
            +
                  expect(n).to be_a(Tempura::Newton)
         
     | 
| 
      
 32 
     | 
    
         
            +
                end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                it 'converts to rankine' do
         
     | 
| 
      
 35 
     | 
    
         
            +
                  expect(ra).to be_a(Tempura::Rankine)
         
     | 
| 
      
 36 
     | 
    
         
            +
                end
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                it 'converts to réaumur' do
         
     | 
| 
      
 39 
     | 
    
         
            +
                  expect(ré).to be_a(Tempura::Réaumur)
         
     | 
| 
      
 40 
     | 
    
         
            +
                  expect(re).to be_a(Tempura::Réaumur)
         
     | 
| 
      
 41 
     | 
    
         
            +
                end
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                it 'converts to rømer' do
         
     | 
| 
      
 44 
     | 
    
         
            +
                  expect(rø).to be_a(Tempura::Rømer)
         
     | 
| 
      
 45 
     | 
    
         
            +
                  expect(ro).to be_a(Tempura::Rømer)
         
     | 
| 
      
 46 
     | 
    
         
            +
                end
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
                it 'correctly converted them all' do
         
     | 
| 
      
 49 
     | 
    
         
            +
                  scales = [c, d, f, n, ra, ré, re, rø, ro]
         
     | 
| 
      
 50 
     | 
    
         
            +
                  scales.each { |s1|
         
     | 
| 
      
 51 
     | 
    
         
            +
                    scales.each { |s2|
         
     | 
| 
      
 52 
     | 
    
         
            +
                      expect(s1 == s2).to be_true
         
     | 
| 
      
 53 
     | 
    
         
            +
                    }
         
     | 
| 
      
 54 
     | 
    
         
            +
                  }
         
     | 
| 
      
 55 
     | 
    
         
            +
                end
         
     | 
| 
      
 56 
     | 
    
         
            +
              end
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -54,7 +54,7 @@ describe Tempura::Temperature do 
     | 
|
| 
       54 
54 
     | 
    
         
             
                  c = Tempura::Celsius.new(100)
         
     | 
| 
       55 
55 
     | 
    
         
             
                  r = Tempura::Rømer.new(60)
         
     | 
| 
       56 
56 
     | 
    
         
             
                  k = Tempura::Kelvin.new(373.15)
         
     | 
| 
       57 
     | 
    
         
            -
                  result = ((f + c + r + k) / 4 ). 
     | 
| 
      
 57 
     | 
    
         
            +
                  result = ((f + c + r + k) / 4 ).to.delisle
         
     | 
| 
       58 
58 
     | 
    
         
             
                  expect(result).to eq(0)
         
     | 
| 
       59 
59 
     | 
    
         
             
                  expect(result).to be_a(Tempura::Delisle)
         
     | 
| 
       60 
60 
     | 
    
         
             
                end
         
     | 
| 
         @@ -64,8 +64,8 @@ describe Tempura::Temperature do 
     | 
|
| 
       64 
64 
     | 
    
         
             
                it 'compares internal value' do
         
     | 
| 
       65 
65 
     | 
    
         
             
                  fahrenheit = Tempura::Fahrenheit.new(212)
         
     | 
| 
       66 
66 
     | 
    
         
             
                  celsius = Tempura::Celsius.new(101)
         
     | 
| 
       67 
     | 
    
         
            -
                   
     | 
| 
       68 
     | 
    
         
            -
                  expect( 
     | 
| 
      
 67 
     | 
    
         
            +
                  comp = fahrenheit <=> celsius
         
     | 
| 
      
 68 
     | 
    
         
            +
                  expect(comp).to eq(-1)
         
     | 
| 
       69 
69 
     | 
    
         
             
                end
         
     | 
| 
       70 
70 
     | 
    
         | 
| 
       71 
71 
     | 
    
         
             
                describe 'comparison operators' do
         
     | 
    
        data/tempura.gemspec
    CHANGED
    
    | 
         @@ -18,7 +18,9 @@ Gem::Specification.new do |gem| 
     | 
|
| 
       18 
18 
     | 
    
         
             
                                    README.md
         
     | 
| 
       19 
19 
     | 
    
         
             
                                    Rakefile
         
     | 
| 
       20 
20 
     | 
    
         
             
                                    lib/tempura.rb
         
     | 
| 
      
 21 
     | 
    
         
            +
                                    lib/tempura/core_ext/numeric.rb
         
     | 
| 
       21 
22 
     | 
    
         
             
                                    lib/tempura/celsius.rb
         
     | 
| 
      
 23 
     | 
    
         
            +
                                    lib/tempura/conversion.rb
         
     | 
| 
       22 
24 
     | 
    
         
             
                                    lib/tempura/delisle.rb
         
     | 
| 
       23 
25 
     | 
    
         
             
                                    lib/tempura/fahrenheit.rb
         
     | 
| 
       24 
26 
     | 
    
         
             
                                    lib/tempura/kelvin.rb
         
     | 
| 
         @@ -30,6 +32,8 @@ Gem::Specification.new do |gem| 
     | 
|
| 
       30 
32 
     | 
    
         
             
                                    lib/tempura/version.rb
         
     | 
| 
       31 
33 
     | 
    
         
             
                                    spec/spec_helper.rb
         
     | 
| 
       32 
34 
     | 
    
         
             
                                    spec/tempura/celsius_spec.rb
         
     | 
| 
      
 35 
     | 
    
         
            +
                                    spec/tempura/conversion_spec.rb
         
     | 
| 
      
 36 
     | 
    
         
            +
                                    spec/tempura/core_ext_spec.rb
         
     | 
| 
       33 
37 
     | 
    
         
             
                                    spec/tempura/delisle_spec.rb
         
     | 
| 
       34 
38 
     | 
    
         
             
                                    spec/tempura/fahrenheit_spec.rb
         
     | 
| 
       35 
39 
     | 
    
         
             
                                    spec/tempura/kelvin_spec.rb
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: tempura
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.0 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.1.0
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors:
         
     | 
| 
         @@ -9,7 +9,7 @@ authors: 
     | 
|
| 
       9 
9 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       10 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       11 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       12 
     | 
    
         
            -
            date: 2013-02- 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2013-02-24 00:00:00.000000000 Z
         
     | 
| 
       13 
13 
     | 
    
         
             
            dependencies:
         
     | 
| 
       14 
14 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       15 
15 
     | 
    
         
             
              name: rspec
         
     | 
| 
         @@ -41,7 +41,9 @@ files: 
     | 
|
| 
       41 
41 
     | 
    
         
             
            - README.md
         
     | 
| 
       42 
42 
     | 
    
         
             
            - Rakefile
         
     | 
| 
       43 
43 
     | 
    
         
             
            - lib/tempura.rb
         
     | 
| 
      
 44 
     | 
    
         
            +
            - lib/tempura/core_ext/numeric.rb
         
     | 
| 
       44 
45 
     | 
    
         
             
            - lib/tempura/celsius.rb
         
     | 
| 
      
 46 
     | 
    
         
            +
            - lib/tempura/conversion.rb
         
     | 
| 
       45 
47 
     | 
    
         
             
            - lib/tempura/delisle.rb
         
     | 
| 
       46 
48 
     | 
    
         
             
            - lib/tempura/fahrenheit.rb
         
     | 
| 
       47 
49 
     | 
    
         
             
            - lib/tempura/kelvin.rb
         
     | 
| 
         @@ -53,6 +55,8 @@ files: 
     | 
|
| 
       53 
55 
     | 
    
         
             
            - lib/tempura/version.rb
         
     | 
| 
       54 
56 
     | 
    
         
             
            - spec/spec_helper.rb
         
     | 
| 
       55 
57 
     | 
    
         
             
            - spec/tempura/celsius_spec.rb
         
     | 
| 
      
 58 
     | 
    
         
            +
            - spec/tempura/conversion_spec.rb
         
     | 
| 
      
 59 
     | 
    
         
            +
            - spec/tempura/core_ext_spec.rb
         
     | 
| 
       56 
60 
     | 
    
         
             
            - spec/tempura/delisle_spec.rb
         
     | 
| 
       57 
61 
     | 
    
         
             
            - spec/tempura/fahrenheit_spec.rb
         
     | 
| 
       58 
62 
     | 
    
         
             
            - spec/tempura/kelvin_spec.rb
         
     | 
| 
         @@ -76,7 +80,7 @@ required_ruby_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       76 
80 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       77 
81 
     | 
    
         
             
                  segments:
         
     | 
| 
       78 
82 
     | 
    
         
             
                  - 0
         
     | 
| 
       79 
     | 
    
         
            -
                  hash:  
     | 
| 
      
 83 
     | 
    
         
            +
                  hash: 2341544860719829605
         
     | 
| 
       80 
84 
     | 
    
         
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
       81 
85 
     | 
    
         
             
              none: false
         
     | 
| 
       82 
86 
     | 
    
         
             
              requirements:
         
     | 
| 
         @@ -85,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       85 
89 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       86 
90 
     | 
    
         
             
                  segments:
         
     | 
| 
       87 
91 
     | 
    
         
             
                  - 0
         
     | 
| 
       88 
     | 
    
         
            -
                  hash:  
     | 
| 
      
 92 
     | 
    
         
            +
                  hash: 2341544860719829605
         
     | 
| 
       89 
93 
     | 
    
         
             
            requirements: []
         
     | 
| 
       90 
94 
     | 
    
         
             
            rubyforge_project: 
         
     | 
| 
       91 
95 
     | 
    
         
             
            rubygems_version: 1.8.23
         
     | 
| 
         @@ -95,6 +99,8 @@ summary: Tempura is a library for temperature math and conversion. 
     | 
|
| 
       95 
99 
     | 
    
         
             
            test_files:
         
     | 
| 
       96 
100 
     | 
    
         
             
            - spec/spec_helper.rb
         
     | 
| 
       97 
101 
     | 
    
         
             
            - spec/tempura/celsius_spec.rb
         
     | 
| 
      
 102 
     | 
    
         
            +
            - spec/tempura/conversion_spec.rb
         
     | 
| 
      
 103 
     | 
    
         
            +
            - spec/tempura/core_ext_spec.rb
         
     | 
| 
       98 
104 
     | 
    
         
             
            - spec/tempura/delisle_spec.rb
         
     | 
| 
       99 
105 
     | 
    
         
             
            - spec/tempura/fahrenheit_spec.rb
         
     | 
| 
       100 
106 
     | 
    
         
             
            - spec/tempura/kelvin_spec.rb
         
     |