phys-units 0.9.1 → 0.9.2

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.
@@ -50,11 +50,12 @@ module Phys
50
50
  end
51
51
 
52
52
  def word(x)
53
- find_unit(x) || define(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
- ( /(.{3,}(?:s|z|ch))es$/ =~ x && LIST[$1] ) ||
75
- ( /(.{3,})s$/ =~ x && LIST[$1] )
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*+\\/0-9<=>()\\[\\]^{|}~\\\\'
90
+ '\\s*+\\/<=>()\\[\\]^{|}~\\\\'
90
91
  end
91
92
 
92
93
  def control_units_dat(var,skip,line)
@@ -1,5 +1,5 @@
1
1
  module Phys
2
2
  class Unit
3
- VERSION = "0.9.1"
3
+ VERSION = "0.9.2"
4
4
  end
5
5
  end
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