measured 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/measured/conversion.rb +4 -0
- data/lib/measured/measurable.rb +8 -2
- data/lib/measured/version.rb +1 -1
- data/test/conversion_test.rb +4 -0
- data/test/measurable_test.rb +5 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0036468352e098a2fa434a576a3a802078666f8
|
4
|
+
data.tar.gz: 2e0d6385ada089335c87ebb8e79da28bfcd826bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d206778b9f16b8fa24c281a68bae304f76325ef9aba6a9d7bdcfe183438beb71f8858a8d77587e54723e67e350f841e5830ed63766758e10432a241671536a92
|
7
|
+
data.tar.gz: 88e4bf7c581f6fb755d9c8cf435a0bc4ef025429b22a57a388d66c7f65862cd9c36e04a752970a94e8fe183d41db441df628a64bf751fbffe122545936cfdcdd
|
data/lib/measured/conversion.rb
CHANGED
data/lib/measured/measurable.rb
CHANGED
@@ -7,8 +7,14 @@ class Measured::Measurable
|
|
7
7
|
def initialize(value, unit)
|
8
8
|
raise Measured::UnitError, "Unit #{ unit } does not exits." unless self.class.conversion.unit_or_alias?(unit)
|
9
9
|
|
10
|
-
@value = value
|
11
|
-
|
10
|
+
@value = case value
|
11
|
+
when Float
|
12
|
+
BigDecimal(value, self.class.conversion.significant_digits)
|
13
|
+
when BigDecimal
|
14
|
+
value
|
15
|
+
else
|
16
|
+
BigDecimal(value)
|
17
|
+
end
|
12
18
|
|
13
19
|
@unit = self.class.conversion.to_unit_name(unit)
|
14
20
|
end
|
data/lib/measured/version.rb
CHANGED
data/test/conversion_test.rb
CHANGED
@@ -98,6 +98,10 @@ class Measured::ConversionTest < ActiveSupport::TestCase
|
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
101
|
+
test "#significatn_digits is fixed for now" do
|
102
|
+
assert_equal 6, @conversion.significant_digits
|
103
|
+
end
|
104
|
+
|
101
105
|
test "#convert raises if either unit is not found" do
|
102
106
|
assert_raises Measured::UnitError do
|
103
107
|
Magic.conversion.convert(1, from: "fire", to: "doesnt_exist")
|
data/test/measurable_test.rb
CHANGED
@@ -33,6 +33,10 @@ class Measured::MeasurableTest < ActiveSupport::TestCase
|
|
33
33
|
assert_equal BigDecimal("5"), Magic.new("5", :arcane).value
|
34
34
|
end
|
35
35
|
|
36
|
+
test "#initialize converts floats to strings and then to BigDecimal so it does not raise" do
|
37
|
+
assert_equal BigDecimal("1.2345"), Magic.new(1.2345, :fire).value
|
38
|
+
end
|
39
|
+
|
36
40
|
test "#initialize converts to the base unit name" do
|
37
41
|
assert_equal "fireball", Magic.new(1, :fire).unit
|
38
42
|
end
|
@@ -100,7 +104,7 @@ class Measured::MeasurableTest < ActiveSupport::TestCase
|
|
100
104
|
|
101
105
|
test "#inspect shows the number and the unit" do
|
102
106
|
assert_equal "#<Magic: 0.1E2 fireball>", Magic.new(10, :fire).inspect
|
103
|
-
assert_equal "#<Magic: 0.1234E1 magic_missile>", Magic.new(
|
107
|
+
assert_equal "#<Magic: 0.1234E1 magic_missile>", Magic.new(1.234, :magic_missile).inspect
|
104
108
|
end
|
105
109
|
|
106
110
|
test "#<=> compares only if the class and unit are the same" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: measured
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin McPhillips
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|