chemistry 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +0 -1
- data/Rakefile +2 -1
- data/lib/chemistry.rb +0 -8
- data/lib/chemistry/{element/dsl.rb → dsl.rb} +1 -1
- data/lib/chemistry/element/beryllium.rb +7 -0
- data/lib/chemistry/element/boron.rb +7 -0
- data/lib/chemistry/element/helium.rb +7 -0
- data/lib/chemistry/element/hydrogen.rb +7 -0
- data/lib/chemistry/element/lithium.rb +7 -0
- data/lib/chemistry/temperature.rb +33 -0
- data/lib/chemistry/temperature/celsius.rb +27 -0
- data/lib/chemistry/temperature/fahrenheit.rb +23 -0
- data/lib/chemistry/temperature/kelvin.rb +23 -0
- data/lib/chemistry/version.rb +1 -1
- data/test/chemistry/temperature/test_celsius.rb +28 -0
- data/test/chemistry/temperature/test_fahrenheit.rb +15 -0
- data/test/chemistry/temperature/test_kelvin.rb +28 -0
- data/test/chemistry/{element/test_dsl.rb → test_dsl.rb} +6 -6
- data/test/chemistry/test_temperature.rb +36 -0
- data/test/test_chemistry.rb +0 -4
- metadata +24 -7
data/.travis.yml
CHANGED
data/Rakefile
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
2
|
|
3
|
-
LIB_FILES = FileList.new('lib/**/*.rb').
|
3
|
+
LIB_FILES = FileList.new('lib/**/*.rb').
|
4
|
+
exclude('lib/chemistry/version.rb', 'lib/chemistry/element/*.rb')
|
4
5
|
TEST_FILES = LIB_FILES.pathmap('%{^lib,test}d/test_%f')
|
5
6
|
|
6
7
|
task :test do
|
data/lib/chemistry.rb
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'chemistry/temperature/kelvin'
|
2
|
+
require 'chemistry/temperature/fahrenheit'
|
3
|
+
require 'chemistry/temperature/celsius'
|
4
|
+
|
5
|
+
module Chemistry
|
6
|
+
class Temperature
|
7
|
+
class << self
|
8
|
+
def kelvin(temperature)
|
9
|
+
Chemistry::Temperature::Kelvin.new(temperature)
|
10
|
+
end
|
11
|
+
|
12
|
+
def celsius(temperature)
|
13
|
+
Chemistry::Temperature::Celsius.new(temperature)
|
14
|
+
end
|
15
|
+
|
16
|
+
def fahrenheit(temperature)
|
17
|
+
Chemistry::Temperature::Fahrenheit.new(temperature)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(temperature)
|
22
|
+
@temperature = temperature
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_i
|
26
|
+
@temperature.to_i
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_f
|
30
|
+
@temperature.to_f
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'chemistry/temperature'
|
2
|
+
|
3
|
+
module Chemistry
|
4
|
+
class Temperature
|
5
|
+
class Celsius < Chemistry::Temperature
|
6
|
+
def to_celsius
|
7
|
+
self
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_kelvin
|
11
|
+
Chemistry::Temperature.kelvin convert_to_kelvin
|
12
|
+
end
|
13
|
+
|
14
|
+
def convert_to_kelvin
|
15
|
+
@temperature + 273.15
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_fahrenheit
|
19
|
+
Chemistry::Temperature.fahrenheit convert_to_fahrenheit
|
20
|
+
end
|
21
|
+
|
22
|
+
def convert_to_fahrenheit
|
23
|
+
(@temperature * (9.0/5.0)) + 32.0
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'chemistry/temperature'
|
2
|
+
|
3
|
+
module Chemistry
|
4
|
+
class Temperature
|
5
|
+
class Fahrenheit < Chemistry::Temperature
|
6
|
+
def to_fahrenheit
|
7
|
+
self
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_kelvin
|
11
|
+
to_celsius.to_kelvin
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_celsius
|
15
|
+
Chemistry::Temperature.celsius convert_to_celsius
|
16
|
+
end
|
17
|
+
|
18
|
+
def convert_to_celsius
|
19
|
+
(@temperature - 32.0) / (9.0/5.0)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'chemistry/temperature'
|
2
|
+
|
3
|
+
module Chemistry
|
4
|
+
class Temperature
|
5
|
+
class Kelvin < Chemistry::Temperature
|
6
|
+
def to_kelvin
|
7
|
+
self
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_celsius
|
11
|
+
Chemistry::Temperature.celsius convert_to_celsius
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_fahrenheit
|
15
|
+
to_celsius.to_fahrenheit
|
16
|
+
end
|
17
|
+
|
18
|
+
def convert_to_celsius
|
19
|
+
@temperature - 273.15
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/chemistry/version.rb
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ToCelsiusTest < MiniTest::Unit::TestCase
|
4
|
+
def test_returns_self
|
5
|
+
temp = Chemistry::Temperature::Celsius.new(1)
|
6
|
+
assert_equal temp, temp.to_celsius
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class ToKelvinTest < MiniTest::Unit::TestCase
|
11
|
+
def test_instance_of_kelvin
|
12
|
+
temp = Chemistry::Temperature::Celsius.new(1)
|
13
|
+
assert temp.to_kelvin.instance_of? Chemistry::Temperature::Kelvin
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_difference_of_273
|
17
|
+
base = 1
|
18
|
+
temp = Chemistry::Temperature::Celsius.new(base)
|
19
|
+
assert_equal (temp.to_i - temp.to_kelvin.to_i).abs, 273
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class ToFahrenheitTest < MiniTest::Unit::TestCase
|
24
|
+
def test_0C_is_32F
|
25
|
+
temp = Chemistry::Temperature::Celsius.new(0)
|
26
|
+
assert_equal temp.to_fahrenheit.to_i, 32
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ToFahrenheitTest < MiniTest::Unit::TestCase
|
4
|
+
def test_returns_self
|
5
|
+
temp = Chemistry::Temperature::Fahrenheit.new(1)
|
6
|
+
assert_equal temp, temp.to_fahrenheit
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class ToCelsiusTest < MiniTest::Unit::TestCase
|
11
|
+
def test_32F_is_0C
|
12
|
+
temp = Chemistry::Temperature::Fahrenheit.new(32)
|
13
|
+
assert_equal temp.to_celsius.to_i, 0
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ToKelvinTest < MiniTest::Unit::TestCase
|
4
|
+
def test_returns_self
|
5
|
+
temp = Chemistry::Temperature::Kelvin.new(1)
|
6
|
+
assert_equal temp, temp.to_kelvin
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class ToCelsiusTest < MiniTest::Unit::TestCase
|
11
|
+
def test_instance_of_celsius
|
12
|
+
temp = Chemistry::Temperature::Kelvin.new(1)
|
13
|
+
assert temp.to_celsius.instance_of? Chemistry::Temperature::Celsius
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_difference_of_273
|
17
|
+
base = 1
|
18
|
+
temp = Chemistry::Temperature::Kelvin.new(base)
|
19
|
+
assert_equal (temp.to_i - temp.to_celsius.to_i).abs, 273
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class ToFahrenheitTest < MiniTest::Unit::TestCase
|
24
|
+
def test_273_15K_is_32F
|
25
|
+
temp = Chemistry::Temperature::Kelvin.new(273.15)
|
26
|
+
assert_equal temp.to_fahrenheit.to_i, 32
|
27
|
+
end
|
28
|
+
end
|
@@ -3,30 +3,30 @@ require 'test_helper'
|
|
3
3
|
class ElementTest < MiniTest::Unit::TestCase
|
4
4
|
def test_raises_error_without_name
|
5
5
|
assert_raises ArgumentError do
|
6
|
-
|
6
|
+
Chemistry::DSL.element
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
10
|
def test_raises_error_without_block
|
11
11
|
assert_raises ArgumentError do
|
12
|
-
Chemistry::
|
12
|
+
Chemistry::DSL.element "Hydrogen"
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
def test_defines_an_element
|
17
17
|
assert_raises NameError do
|
18
|
-
|
18
|
+
Chemistry::Element::Foobar
|
19
19
|
end
|
20
20
|
|
21
|
-
|
21
|
+
Chemistry::DSL.element "Foobar" do
|
22
22
|
end
|
23
23
|
|
24
|
-
assert_equal
|
24
|
+
assert_equal Chemistry::Element <=> Chemistry::Element::Foobar, 1
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
class DefinitionTest < MiniTest::Unit::TestCase
|
29
|
-
include Chemistry::
|
29
|
+
include Chemistry::DSL
|
30
30
|
|
31
31
|
def test_full_definition
|
32
32
|
element "Hydrogen" do
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class KelvinTest < MiniTest::Unit::TestCase
|
4
|
+
def test_returns_kelvin_wrapper
|
5
|
+
assert Chemistry::Temperature.kelvin(1).
|
6
|
+
instance_of?(Chemistry::Temperature::Kelvin)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class ToITest < MiniTest::Unit::TestCase
|
11
|
+
def test_returns_temperature
|
12
|
+
temp = 1
|
13
|
+
assert_equal Chemistry::Temperature.new(temp).to_i, temp.to_i
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class ToFTest < MiniTest::Unit::TestCase
|
18
|
+
def test_returns_temperature
|
19
|
+
temp = 1.0
|
20
|
+
assert_equal Chemistry::Temperature.new(temp).to_f, temp.to_f
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class FahrenheitTest < MiniTest::Unit::TestCase
|
25
|
+
def test_returns_fahrenheit_wrapper
|
26
|
+
assert Chemistry::Temperature.fahrenheit(1).
|
27
|
+
instance_of?(Chemistry::Temperature::Fahrenheit)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class CelsiusTest < MiniTest::Unit::TestCase
|
32
|
+
def test_returns_celsius_wrapper
|
33
|
+
assert Chemistry::Temperature.celsius(1).
|
34
|
+
instance_of?(Chemistry::Temperature::Celsius)
|
35
|
+
end
|
36
|
+
end
|
data/test/test_chemistry.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chemistry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
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: 2012-08-
|
12
|
+
date: 2012-08-09 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Chemistry is a toolkit for dealing with compounds
|
15
15
|
email:
|
@@ -26,11 +26,24 @@ files:
|
|
26
26
|
- Rakefile
|
27
27
|
- chemistry.gemspec
|
28
28
|
- lib/chemistry.rb
|
29
|
+
- lib/chemistry/dsl.rb
|
29
30
|
- lib/chemistry/element.rb
|
30
|
-
- lib/chemistry/element/
|
31
|
+
- lib/chemistry/element/beryllium.rb
|
32
|
+
- lib/chemistry/element/boron.rb
|
33
|
+
- lib/chemistry/element/helium.rb
|
34
|
+
- lib/chemistry/element/hydrogen.rb
|
35
|
+
- lib/chemistry/element/lithium.rb
|
36
|
+
- lib/chemistry/temperature.rb
|
37
|
+
- lib/chemistry/temperature/celsius.rb
|
38
|
+
- lib/chemistry/temperature/fahrenheit.rb
|
39
|
+
- lib/chemistry/temperature/kelvin.rb
|
31
40
|
- lib/chemistry/version.rb
|
32
|
-
- test/chemistry/
|
41
|
+
- test/chemistry/temperature/test_celsius.rb
|
42
|
+
- test/chemistry/temperature/test_fahrenheit.rb
|
43
|
+
- test/chemistry/temperature/test_kelvin.rb
|
44
|
+
- test/chemistry/test_dsl.rb
|
33
45
|
- test/chemistry/test_element.rb
|
46
|
+
- test/chemistry/test_temperature.rb
|
34
47
|
- test/test_chemistry.rb
|
35
48
|
- test/test_helper.rb
|
36
49
|
homepage: http://isaacbfsanders.com/chemistry
|
@@ -47,7 +60,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
47
60
|
version: '0'
|
48
61
|
segments:
|
49
62
|
- 0
|
50
|
-
hash: -
|
63
|
+
hash: -1034708689434177440
|
51
64
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
65
|
none: false
|
53
66
|
requirements:
|
@@ -56,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
69
|
version: '0'
|
57
70
|
segments:
|
58
71
|
- 0
|
59
|
-
hash: -
|
72
|
+
hash: -1034708689434177440
|
60
73
|
requirements: []
|
61
74
|
rubyforge_project:
|
62
75
|
rubygems_version: 1.8.24
|
@@ -64,7 +77,11 @@ signing_key:
|
|
64
77
|
specification_version: 3
|
65
78
|
summary: Chemistry is a toolkit for dealing with compounds
|
66
79
|
test_files:
|
67
|
-
- test/chemistry/
|
80
|
+
- test/chemistry/temperature/test_celsius.rb
|
81
|
+
- test/chemistry/temperature/test_fahrenheit.rb
|
82
|
+
- test/chemistry/temperature/test_kelvin.rb
|
83
|
+
- test/chemistry/test_dsl.rb
|
68
84
|
- test/chemistry/test_element.rb
|
85
|
+
- test/chemistry/test_temperature.rb
|
69
86
|
- test/test_chemistry.rb
|
70
87
|
- test/test_helper.rb
|