unitwise 0.2.0 → 0.2.1
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/Gemfile +1 -0
- data/lib/unitwise/expression.rb +10 -4
- data/lib/unitwise/ext/numeric.rb +3 -5
- data/lib/unitwise/measurement.rb +7 -0
- data/lib/unitwise/scale.rb +4 -0
- data/lib/unitwise/unit.rb +0 -1
- data/lib/unitwise/version.rb +1 -1
- data/test/unitwise/measurement_test.rb +3 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7cf611ec88dbc4e07823a8237da220ddc2747dd0
|
4
|
+
data.tar.gz: 8efa28b4bbf55900b05cac6f25655b9fe6476f11
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e2dc02863b592f53e73912d43c536388a54dad320dff00c28855645aa9e59071e9328ea7c12a8c151db567e476160179efc404e6898df7955d5e940ca8f7b10
|
7
|
+
data.tar.gz: 5775f6a107d7b953bb40a38edcde038b88ba20c020049c67eb747cba29fdf9803f6b7a23c320d4db7f404eadb90a7cf7327a1d3e299f00d93bbca9b37c2e2298
|
data/Gemfile
CHANGED
data/lib/unitwise/expression.rb
CHANGED
@@ -14,10 +14,16 @@ module Unitwise
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def decompose(expression)
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
expression = expression.to_s
|
18
|
+
@decompose ||= {}
|
19
|
+
if @decompose.has_key?(expression)
|
20
|
+
@decompose[expression]
|
21
|
+
else
|
22
|
+
@decompose[expression] = begin
|
23
|
+
Decomposer.new(expression).terms
|
24
|
+
rescue ExpressionError
|
25
|
+
nil
|
26
|
+
end
|
21
27
|
end
|
22
28
|
end
|
23
29
|
end
|
data/lib/unitwise/ext/numeric.rb
CHANGED
@@ -4,10 +4,8 @@ class Numeric
|
|
4
4
|
end
|
5
5
|
|
6
6
|
def method_missing(meth, *args, &block)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
super(meth, *args, &block)
|
11
|
-
end
|
7
|
+
convert(meth)
|
8
|
+
rescue Unitwise::ExpressionError
|
9
|
+
super(meth, *args)
|
12
10
|
end
|
13
11
|
end
|
data/lib/unitwise/measurement.rb
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
module Unitwise
|
2
2
|
class Measurement < Scale
|
3
3
|
|
4
|
+
def initialize(value, unit)
|
5
|
+
super(value, unit)
|
6
|
+
if terms.nil?
|
7
|
+
raise ExpressionError, "Could not evaluate `#{unit}`."
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
4
11
|
def convert(other_unit)
|
5
12
|
other_unit = Unit.new(other_unit)
|
6
13
|
if similar_to?(other_unit)
|
data/lib/unitwise/scale.rb
CHANGED
data/lib/unitwise/unit.rb
CHANGED
data/lib/unitwise/version.rb
CHANGED
@@ -7,6 +7,9 @@ describe Unitwise::Measurement do
|
|
7
7
|
subject.value.must_equal(1)
|
8
8
|
subject.unit.to_s.must_equal('m/s')
|
9
9
|
end
|
10
|
+
it "should raise an error for unknown units" do
|
11
|
+
->{ Unitwise::Measurement.new(1,"funkitron") }.must_raise(Unitwise::ExpressionError)
|
12
|
+
end
|
10
13
|
end
|
11
14
|
|
12
15
|
describe "#unit" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unitwise
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Lewis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: signed_multiset
|
@@ -210,3 +210,4 @@ test_files:
|
|
210
210
|
- test/unitwise/term_test.rb
|
211
211
|
- test/unitwise/unit_test.rb
|
212
212
|
- test/unitwise_test.rb
|
213
|
+
has_rdoc:
|