phys-units 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +23 -3
- data/lib/phys/units/load_units.rb +5 -105
- data/lib/phys/units/parse.rb +12 -4
- data/lib/phys/units/parse.y +13 -5
- data/lib/phys/units/quantity.rb +56 -35
- data/lib/phys/units/unit.rb +22 -18
- data/lib/phys/units/unit_class.rb +6 -5
- data/lib/phys/units/version.rb +1 -1
- data/spec/helper.rb +22 -0
- data/spec/units_dat_spec.rb +6983 -0
- metadata +4 -2
@@ -50,11 +50,12 @@ module Phys
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def word(x)
|
53
|
-
find_unit(x)
|
53
|
+
find_unit(x) or raise UnitError, "Undefined unit: #{x.inspect}"
|
54
|
+
#find_unit(x) || define(x,nil)
|
54
55
|
end
|
55
56
|
|
56
57
|
def parse(x)
|
57
|
-
find_unit(x) || Parse.new.parse(x)
|
58
|
+
find_unit(x) || Unit.cast(Parse.new.parse(x))
|
58
59
|
end
|
59
60
|
|
60
61
|
def find_unit(x)
|
@@ -71,8 +72,8 @@ module Phys
|
|
71
72
|
alias [] find_unit
|
72
73
|
|
73
74
|
def unit_stem(x)
|
74
|
-
( /(.{
|
75
|
-
( /(.{
|
75
|
+
( /(.{2,}(?:s|z|ch))es$/ =~ x && LIST[$1] ) ||
|
76
|
+
( /(.{2,})s$/ =~ x && LIST[$1] )
|
76
77
|
end
|
77
78
|
|
78
79
|
def find_prefix(x)
|
@@ -86,7 +87,7 @@ module Phys
|
|
86
87
|
#--
|
87
88
|
|
88
89
|
def unit_chars
|
89
|
-
'\\s
|
90
|
+
'\\s*+\\/<=>()\\[\\]^{|}~\\\\'
|
90
91
|
end
|
91
92
|
|
92
93
|
def control_units_dat(var,skip,line)
|
data/lib/phys/units/version.rb
CHANGED
data/spec/helper.rb
CHANGED
@@ -1,4 +1,26 @@
|
|
1
1
|
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
|
2
2
|
require "phys/units"
|
3
|
+
|
3
4
|
U = Phys::Unit
|
4
5
|
Q = Phys::Quantity
|
6
|
+
|
7
|
+
RSpec::Matchers.define :be_sfloat_close_to do |y|
|
8
|
+
match do |x|
|
9
|
+
if x==0 && y==0
|
10
|
+
true
|
11
|
+
else
|
12
|
+
x = x.to_f
|
13
|
+
(x-y).abs/(x.abs+y.abs) < 1.2e-7
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
RSpec::Matchers.define :be_a_quantity_close_to do |expected|
|
19
|
+
match do |actual|
|
20
|
+
if !(Phys::Quantity===actual && Phys::Quantity===expected)
|
21
|
+
false
|
22
|
+
else
|
23
|
+
actual.close_to(expected,1.2e-7)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|