measured 0.0.8 → 0.0.9
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.
- checksums.yaml +4 -4
- data/lib/measured/measurable.rb +7 -2
- data/lib/measured/version.rb +1 -1
- data/test/measurable_test.rb +24 -2
- 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: d67a6033c4e3bb7faa0f4ee02a2b3ec482c38c12
|
4
|
+
data.tar.gz: 1735180f229b2ecc51795ea6be26041eccbaa16d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ff858d2b73a86fc12749ebe26659f8e4bb46738fa9d34412a8aa579c32b0df20b71a2079d0f4bf31024b212ef8dc82ffc6b9e1b1fc2565851d0d6bbcae11b3b
|
7
|
+
data.tar.gz: da420ab2472759e797bc2a98319c8ae85a55bdf9a7342c9eeb49e5ba02504ca64082849e4c01af4d3847871d0c6a5004b527d7b804915bd47be66b0b9667b242
|
data/lib/measured/measurable.rb
CHANGED
@@ -5,7 +5,8 @@ class Measured::Measurable
|
|
5
5
|
attr_reader :unit, :value
|
6
6
|
|
7
7
|
def initialize(value, unit)
|
8
|
-
raise Measured::UnitError, "Unit
|
8
|
+
raise Measured::UnitError, "Unit cannot be blank" if unit.blank?
|
9
|
+
raise Measured::UnitError, "Unit #{ unit } does not exits" unless self.class.conversion.unit_or_alias?(unit)
|
9
10
|
|
10
11
|
@value = case value
|
11
12
|
when NilClass
|
@@ -15,7 +16,11 @@ class Measured::Measurable
|
|
15
16
|
when BigDecimal
|
16
17
|
value
|
17
18
|
else
|
18
|
-
|
19
|
+
if value.blank?
|
20
|
+
raise Measured::UnitError, "Unit value cannot be blank"
|
21
|
+
else
|
22
|
+
BigDecimal(value)
|
23
|
+
end
|
19
24
|
end
|
20
25
|
|
21
26
|
@unit = self.class.conversion.to_unit_name(unit)
|
data/lib/measured/version.rb
CHANGED
data/test/measurable_test.rb
CHANGED
@@ -46,10 +46,32 @@ class Measured::MeasurableTest < ActiveSupport::TestCase
|
|
46
46
|
assert_equal "fireball", Magic.new(1, :fire).unit
|
47
47
|
end
|
48
48
|
|
49
|
-
test "#initialize raises an expected error when initializing with nil" do
|
50
|
-
assert_raises
|
49
|
+
test "#initialize raises an expected error when initializing with nil value" do
|
50
|
+
exception = assert_raises(Measured::UnitError) do
|
51
51
|
Magic.new(nil, :fire)
|
52
52
|
end
|
53
|
+
assert_equal "Unit value cannot be nil", exception.message
|
54
|
+
end
|
55
|
+
|
56
|
+
test "#initialize raises an expected error when initializing with nil unit" do
|
57
|
+
exception = assert_raises(Measured::UnitError) do
|
58
|
+
Magic.new(1, nil)
|
59
|
+
end
|
60
|
+
assert_equal "Unit cannot be blank", exception.message
|
61
|
+
end
|
62
|
+
|
63
|
+
test "#initialize raises an expected error when initializing with empty string value" do
|
64
|
+
exception = assert_raises(Measured::UnitError) do
|
65
|
+
Magic.new("", :fire)
|
66
|
+
end
|
67
|
+
assert_equal "Unit value cannot be blank", exception.message
|
68
|
+
end
|
69
|
+
|
70
|
+
test "#initialize raises an expected error when initializing with empty string unit" do
|
71
|
+
exception = assert_raises(Measured::UnitError) do
|
72
|
+
Magic.new(1, "")
|
73
|
+
end
|
74
|
+
assert_equal "Unit cannot be blank", exception.message
|
53
75
|
end
|
54
76
|
|
55
77
|
test "#unit allows you to read the unit string" 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.9
|
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-06-
|
11
|
+
date: 2015-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|