ruby-units 1.2.0 → 1.3.0.a
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.
- data/TODO +2 -3
- data/spec/ruby-units/array_spec.rb +14 -0
- data/spec/ruby-units/complex_spec.rb +37 -0
- data/spec/ruby-units/date_spec.rb +38 -0
- data/spec/ruby-units/math_spec.rb +63 -0
- data/spec/ruby-units/numeric_spec.rb +12 -0
- data/spec/ruby-units/object_spec.rb +7 -0
- data/spec/ruby-units/string_spec.rb +65 -0
- data/spec/ruby-units/time_spec.rb +28 -0
- data/spec/ruby-units/unit_spec.rb +855 -0
- data/spec/spec_helper.rb +4 -0
- data/test/test_cache.rb +26 -0
- data/test/test_ruby-units.rb +40 -11
- metadata +49 -59
- data/CHANGELOG.txt +0 -206
- data/Gemfile +0 -7
- data/Manifest.txt +0 -19
- data/RakeFile +0 -40
- data/VERSION +0 -1
- data/lib/ruby-units.rb +0 -13
- data/lib/ruby_units.rb +0 -13
- data/lib/ruby_units/array.rb +0 -9
- data/lib/ruby_units/cmath.rb +0 -2
- data/lib/ruby_units/complex.rb +0 -10
- data/lib/ruby_units/date.rb +0 -57
- data/lib/ruby_units/math.rb +0 -101
- data/lib/ruby_units/numeric.rb +0 -8
- data/lib/ruby_units/object.rb +0 -8
- data/lib/ruby_units/ruby-units.rb +0 -1161
- data/lib/ruby_units/string.rb +0 -118
- data/lib/ruby_units/time.rb +0 -73
- data/lib/ruby_units/units.rb +0 -248
- data/lib/ruby_units/version.rb +0 -5
- data/ruby-units.gemspec +0 -73
data/lib/ruby_units/string.rb
DELETED
@@ -1,118 +0,0 @@
|
|
1
|
-
require 'time'
|
2
|
-
# make a string into a unit
|
3
|
-
class String
|
4
|
-
def to_unit(other = nil)
|
5
|
-
other ? Unit.new(self).to(other) : Unit.new(self)
|
6
|
-
end
|
7
|
-
alias :unit :to_unit
|
8
|
-
alias :u :to_unit
|
9
|
-
alias :unit_format :%
|
10
|
-
|
11
|
-
# format unit output using formating codes '%0.2f' % '1 mm'.unit => '1.00 mm'
|
12
|
-
def %(*args)
|
13
|
-
return if self.empty?
|
14
|
-
case
|
15
|
-
when Unit === args[0]
|
16
|
-
args[0].to_s(self)
|
17
|
-
when (!defined?(Uncertain).nil? && (Uncertain === args[0]))
|
18
|
-
args[0].to_s(self)
|
19
|
-
when Complex === args[0]
|
20
|
-
args[0].to_s
|
21
|
-
else
|
22
|
-
unit_format(*args)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
#needed for compatibility with Rails, which defines a String.from method
|
27
|
-
if self.public_instance_methods.include? 'from'
|
28
|
-
alias :old_from :from
|
29
|
-
end
|
30
|
-
|
31
|
-
def from(time_point = ::Time.now)
|
32
|
-
return old_from(time_point) if Integer === time_point
|
33
|
-
self.unit.from(time_point)
|
34
|
-
end
|
35
|
-
|
36
|
-
alias :after :from
|
37
|
-
alias :from_now :from
|
38
|
-
|
39
|
-
def ago
|
40
|
-
self.unit.ago
|
41
|
-
end
|
42
|
-
|
43
|
-
def before(time_point = ::Time.now)
|
44
|
-
self.unit.before(time_point)
|
45
|
-
end
|
46
|
-
alias :before_now :before
|
47
|
-
|
48
|
-
def since(time_point = ::Time.now)
|
49
|
-
self.unit.since(time_point)
|
50
|
-
end
|
51
|
-
|
52
|
-
def until(time_point = ::Time.now)
|
53
|
-
self.unit.until(time_point)
|
54
|
-
end
|
55
|
-
|
56
|
-
def to(other)
|
57
|
-
self.unit.to(other)
|
58
|
-
end
|
59
|
-
|
60
|
-
def time(options = {})
|
61
|
-
self.to_time(options) rescue self.to_datetime(options)
|
62
|
-
end
|
63
|
-
|
64
|
-
def to_time(options = {})
|
65
|
-
begin
|
66
|
-
#raises exception when Chronic not defined or when it returns a nil (i.e., can't parse the input)
|
67
|
-
r = Chronic.parse(self,options)
|
68
|
-
raise(ArgumentError, 'Invalid Time String') unless r
|
69
|
-
return r
|
70
|
-
rescue
|
71
|
-
case
|
72
|
-
when self == "now"
|
73
|
-
Time.now
|
74
|
-
when Time.respond_to?(:parse)
|
75
|
-
Time.parse(self)
|
76
|
-
else
|
77
|
-
Time.local(*ParseDate.parsedate(self))
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def to_datetime(options = {})
|
83
|
-
begin
|
84
|
-
# raises an exception if Chronic.parse = nil or if Chronic not defined
|
85
|
-
r = Chronic.parse(self,options).send(:to_datetime)
|
86
|
-
rescue Exception => e
|
87
|
-
r = case
|
88
|
-
when self.to_s == "now"
|
89
|
-
DateTime.now
|
90
|
-
else
|
91
|
-
DateTime.parse(self)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
raise RuntimeError, "Invalid Time String (#{self.to_s})" if r == DateTime.new
|
95
|
-
return r
|
96
|
-
end
|
97
|
-
|
98
|
-
def to_date(options={})
|
99
|
-
begin
|
100
|
-
r = Chronic.parse(self,options).to_date
|
101
|
-
rescue
|
102
|
-
r = case
|
103
|
-
when self == "today"
|
104
|
-
Date.today
|
105
|
-
when RUBY_VERSION < "1.9"
|
106
|
-
Date.civil(*ParseDate.parsedate(self)[0..5].compact)
|
107
|
-
else
|
108
|
-
Date.parse(self)
|
109
|
-
end
|
110
|
-
end
|
111
|
-
raise RuntimeError, 'Invalid Date String' if r == Date.new
|
112
|
-
return r
|
113
|
-
end
|
114
|
-
|
115
|
-
def datetime(options = {})
|
116
|
-
self.to_datetime(options) rescue self.to_time(options)
|
117
|
-
end
|
118
|
-
end
|
data/lib/ruby_units/time.rb
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Time math is handled slightly differently. The difference is considered to be an exact duration if
|
3
|
-
# the subtracted value is in hours, minutes, or seconds. It is rounded to the nearest day if the offset
|
4
|
-
# is in years, decades, or centuries. This leads to less precise values, but ones that match the
|
5
|
-
# calendar better.
|
6
|
-
class Time
|
7
|
-
|
8
|
-
class << self
|
9
|
-
alias unit_time_at at
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.at(*args)
|
13
|
-
if Unit === args[0]
|
14
|
-
unit_time_at(args[0].to("s").scalar)
|
15
|
-
else
|
16
|
-
unit_time_at(*args)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def to_unit(other = nil)
|
21
|
-
other ? Unit.new(self).to(other) : Unit.new(self)
|
22
|
-
end
|
23
|
-
alias :unit :to_unit
|
24
|
-
alias :u :to_unit
|
25
|
-
alias :unit_add :+
|
26
|
-
|
27
|
-
unless Time.instance_methods.include?(:to_date)
|
28
|
-
def to_date
|
29
|
-
x=(Date.civil(1970,1,1)+((self.to_f+self.gmt_offset)/86400.0)-0.5)
|
30
|
-
Date.civil(x.year, x.month, x.day)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def +(other)
|
35
|
-
case other
|
36
|
-
when Unit
|
37
|
-
other = other.to('d').round.to('s') if ['y', 'decade', 'century'].include? other.units
|
38
|
-
begin
|
39
|
-
unit_add(other.to('s').scalar)
|
40
|
-
rescue RangeError
|
41
|
-
self.to_datetime + other
|
42
|
-
end
|
43
|
-
when DateTime
|
44
|
-
unit_add(other.to_time)
|
45
|
-
else
|
46
|
-
unit_add(other)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
# usage: Time.in '5 min'
|
51
|
-
def self.in(duration)
|
52
|
-
Time.now + duration.to_unit
|
53
|
-
end
|
54
|
-
|
55
|
-
alias :unit_sub :-
|
56
|
-
|
57
|
-
def -(other)
|
58
|
-
case other
|
59
|
-
when Unit
|
60
|
-
other = other.to('d').round.to('s') if ['y', 'decade', 'century'].include? other.units
|
61
|
-
begin
|
62
|
-
unit_sub(other.to('s').scalar)
|
63
|
-
rescue RangeError
|
64
|
-
self.send(:to_datetime) - other
|
65
|
-
end
|
66
|
-
|
67
|
-
when DateTime
|
68
|
-
unit_sub(other.to_time)
|
69
|
-
else
|
70
|
-
unit_sub(other)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
data/lib/ruby_units/units.rb
DELETED
@@ -1,248 +0,0 @@
|
|
1
|
-
class Unit < Numeric
|
2
|
-
UNIT_DEFINITIONS = {
|
3
|
-
# prefixes
|
4
|
-
'<googol>' => [%w{googol}, 1e100, :prefix],
|
5
|
-
'<kibi>' => [%w{Ki Kibi kibi}, 2**10, :prefix],
|
6
|
-
'<mebi>' => [%w{Mi Mebi mebi}, 2**20, :prefix],
|
7
|
-
'<gibi>' => [%w{Gi Gibi gibi}, 2**30, :prefix],
|
8
|
-
'<tebi>' => [%w{Ti Tebi tebi}, 2**40, :prefix],
|
9
|
-
'<pebi>' => [%w{Pi Pebi pebi}, 2**50, :prefix],
|
10
|
-
'<exi>' => [%w{Ei Exi exi}, 2**60, :prefix],
|
11
|
-
'<zebi>' => [%w{Zi Zebi zebi}, 2**70, :prefix],
|
12
|
-
'<yebi>' => [%w{Yi Yebi yebi}, 2**80, :prefix],
|
13
|
-
'<yotta>' => [%w{Y Yotta yotta}, 1e24, :prefix],
|
14
|
-
'<zetta>' => [%w{Z Zetta zetta}, 1e21, :prefix],
|
15
|
-
'<exa>' => [%w{E Exa exa}, 1e18, :prefix],
|
16
|
-
'<peta>' => [%w{P Peta peta}, 1e15, :prefix],
|
17
|
-
'<tera>' => [%w{T Tera tera}, 1e12, :prefix],
|
18
|
-
'<giga>' => [%w{G Giga giga}, 1e9, :prefix],
|
19
|
-
'<mega>' => [%w{M Mega mega}, 1e6, :prefix],
|
20
|
-
'<kilo>' => [%w{k kilo}, 1e3, :prefix],
|
21
|
-
'<hecto>' => [%w{h Hecto hecto}, 1e2, :prefix],
|
22
|
-
'<deca>' => [%w{da Deca deca deka}, 1e1, :prefix],
|
23
|
-
'<deci>' => [%w{d Deci deci}, 1e-1, :prefix],
|
24
|
-
'<centi>' => [%w{c Centi centi}, 1e-2, :prefix],
|
25
|
-
'<milli>' => [%w{m Milli milli}, 1e-3, :prefix],
|
26
|
-
'<micro>' => [%w{u Micro micro}, 1e-6, :prefix],
|
27
|
-
'<nano>' => [%w{n Nano nano}, 1e-9, :prefix],
|
28
|
-
'<pico>' => [%w{p Pico pico}, 1e-12, :prefix],
|
29
|
-
'<femto>' => [%w{f Femto femto}, 1e-15, :prefix],
|
30
|
-
'<atto>' => [%w{a Atto atto}, 1e-18, :prefix],
|
31
|
-
'<zepto>' => [%w{z Zepto zepto}, 1e-21, :prefix],
|
32
|
-
'<yocto>' => [%w{y Yocto yocto}, 1e-24, :prefix],
|
33
|
-
'<1>' => [%w{1},1,:prefix],
|
34
|
-
|
35
|
-
# length units
|
36
|
-
'<meter>' => [%w{m meter meters metre metres}, 1.0, :length, %w{<meter>} ],
|
37
|
-
'<inch>' => [%w{in inch inches "}, 0.0254, :length, %w{<meter>}],
|
38
|
-
'<foot>' => [%w{ft foot feet '}, 0.3048, :length, %w{<meter>}],
|
39
|
-
'<yard>' => [%w{yd yard yards}, 0.9144, :length, %w{<meter>}],
|
40
|
-
'<mile>' => [%w{mi mile miles}, 1609.344, :length, %w{<meter>}],
|
41
|
-
'<naut-mile>' => [%w{nmi}, 1852, :length, %w{<meter>}],
|
42
|
-
'<league>'=> [%w{league leagues}, 4828, :length, %w{<meter>}],
|
43
|
-
'<furlong>'=> [%w{furlong furlongs}, 201.2, :length, %w{<meter>}],
|
44
|
-
'<rod>' => [%w{rd rod rods}, 5.029, :length, %w{<meter>}],
|
45
|
-
'<mil>' => [%w{mil mils}, 0.0000254, :length, %w{<meter>}],
|
46
|
-
'<angstrom>' =>[%w{ang angstrom angstroms}, 1e-10, :length, %w{<meter>}],
|
47
|
-
'<fathom>' => [%w{fathom fathoms}, 1.829, :length, %w{<meter>}],
|
48
|
-
'<pica>' => [%w{pica picas}, 0.004217, :length, %w{<meter>}],
|
49
|
-
'<point>' => [%w{pt point points}, 0.0003514, :length, %w{<meter>}],
|
50
|
-
'<redshift>' => [%w{z red-shift}, 1.302773e26, :length, %w{<meter>}],
|
51
|
-
'<AU>' => [%w{AU astronomical-unit}, 149597900000, :length, %w{<meter>}],
|
52
|
-
'<light-second>'=>[%w{ls light-second}, 299792500, :length, %w{<meter>}],
|
53
|
-
'<light-minute>'=>[%w{lmin light-minute}, 17987550000, :length, %w{<meter>}],
|
54
|
-
'<light-year>' => [%w{ly light-year}, 9460528000000000, :length, %w{<meter>}],
|
55
|
-
'<parsec>' => [%w{pc parsec parsecs}, 30856780000000000, :length, %w{<meter>}],
|
56
|
-
|
57
|
-
#mass
|
58
|
-
'<kilogram>' => [%w{kg kilogram kilograms}, 1.0, :mass, %w{<kilogram>}],
|
59
|
-
'<AMU>' => [%w{u AMU amu}, 6.0221415e26, :mass, %w{<kilogram>}],
|
60
|
-
'<dalton>' => [%w{Da Dalton Daltons dalton daltons}, 6.0221415e26, :mass, %w{<kilogram>}],
|
61
|
-
'<slug>' => [%w{slug slugs}, 14.5939029, :mass, %w{<kilogram>}],
|
62
|
-
'<short-ton>' => [%w{tn ton}, 907.18474, :mass, %w{<kilogram>}],
|
63
|
-
'<metric-ton>'=>[%w{tonne}, 1000, :mass, %w{<kilogram>}],
|
64
|
-
'<carat>' => [%w{ct carat carats}, 0.0002, :mass, %w{<kilogram>}],
|
65
|
-
'<pound>' => [%w{lbs lb pound pounds #}, 0.45359237, :mass, %w{<kilogram>}],
|
66
|
-
'<ounce>' => [%w{oz ounce ounces}, 0.0283495231, :mass, %w{<kilogram>}],
|
67
|
-
'<gram>' => [%w{g gram grams gramme grammes},1e-3,:mass, %w{<kilogram>}],
|
68
|
-
|
69
|
-
#area
|
70
|
-
'<hectare>'=>[%w{hectare}, 10000, :area, %w{<meter> <meter>}],
|
71
|
-
'<acre>'=>[%w(acre acres), 4046.85642, :area, %w{<meter> <meter>}],
|
72
|
-
'<sqft>'=>[%w(sqft), 1, :area, %w{<feet> <feet>}],
|
73
|
-
|
74
|
-
#volume
|
75
|
-
'<liter>' => [%w{l L liter liters litre litres}, 0.001, :volume, %w{<meter> <meter> <meter>}],
|
76
|
-
'<gallon>'=> [%w{gal gallon gallons}, 0.0037854118, :volume, %w{<meter> <meter> <meter>}],
|
77
|
-
'<quart>'=> [%w{qt quart quarts}, 0.00094635295, :volume, %w{<meter> <meter> <meter>}],
|
78
|
-
'<pint>'=> [%w{pt pint pints}, 0.000473176475, :volume, %w{<meter> <meter> <meter>}],
|
79
|
-
'<cup>'=> [%w{cu cup cups}, 0.000236588238, :volume, %w{<meter> <meter> <meter>}],
|
80
|
-
'<fluid-ounce>'=> [%w{floz fluid-ounce}, 2.95735297e-5, :volume, %w{<meter> <meter> <meter>}],
|
81
|
-
'<tablespoon>'=> [%w{tbs tablespoon tablespoons}, 1.47867648e-5, :volume, %w{<meter> <meter> <meter>}],
|
82
|
-
'<teaspoon>'=> [%w{tsp teaspoon teaspoons}, 4.92892161e-6, :volume, %w{<meter> <meter> <meter>}],
|
83
|
-
|
84
|
-
#speed
|
85
|
-
'<kph>' => [%w{kph}, 0.277777778, :speed, %w{<meter>}, %w{<second>}],
|
86
|
-
'<mph>' => [%w{mph}, 0.44704, :speed, %w{<meter>}, %w{<second>}],
|
87
|
-
'<knot>' => [%w{kt kn kts knot knots}, 0.514444444, :speed, %w{<meter>}, %w{<second>}],
|
88
|
-
'<fps>' => [%w{fps}, 0.3048, :speed, %w{<meter>}, %w{<second>}],
|
89
|
-
|
90
|
-
#acceleration
|
91
|
-
'<gee>' => [%w{gee}, 9.80655, :acceleration, %w{<meter>}, %w{<second> <second>}],
|
92
|
-
|
93
|
-
#temperature_difference
|
94
|
-
'<kelvin>' => [%w{degK kelvin}, 1.0, :temperature, %w{<kelvin>}],
|
95
|
-
'<celsius>' => [%w{degC celsius celsius centigrade}, 1.0, :temperature, %w{<kelvin>}],
|
96
|
-
'<fahrenheit>' => [%w{degF fahrenheit}, 1/1.8, :temperature, %w{<kelvin>}],
|
97
|
-
'<rankine>' => [%w{degR rankine}, 1/1.8, :temperature, %w{<kelvin>}],
|
98
|
-
'<temp-K>' => [%w{tempK}, 1.0, :temperature, %w{<temp-K>}],
|
99
|
-
'<temp-C>' => [%w{tempC}, 1.0, :temperature, %w{<temp-K>}],
|
100
|
-
'<temp-F>' => [%w{tempF}, 1/1.8, :temperature, %w{<temp-K>}],
|
101
|
-
'<temp-R>' => [%w{tempR}, 1/1.8, :temperature, %w{<temp-K>}],
|
102
|
-
|
103
|
-
#time
|
104
|
-
'<second>'=> [%w{s sec second seconds}, 1.0, :time, %w{<second>}],
|
105
|
-
'<minute>'=> [%w{min minute minutes}, 60.0, :time, %w{<second>}],
|
106
|
-
'<hour>'=> [%w{h hr hrs hour hours}, 3600.0, :time, %w{<second>}],
|
107
|
-
'<day>'=> [%w{d day days}, 3600*24, :time, %w{<second>}],
|
108
|
-
'<week>'=> [%w{wk week weeks}, 7*3600*24, :time, %w{<second>}],
|
109
|
-
'<fortnight>'=> [%w{fortnight fortnights}, 1209600, :time, %W{<second>}],
|
110
|
-
'<year>'=> [%w{y yr year years annum}, 31556926, :time, %w{<second>}],
|
111
|
-
'<decade>'=>[%w{decade decades}, 315569260, :time, %w{<second>}],
|
112
|
-
'<century>'=>[%w{century centuries}, 3155692600, :time, %w{<second>}],
|
113
|
-
|
114
|
-
#pressure
|
115
|
-
'<pascal>' => [%w{Pa pascal Pascal}, 1.0, :pressure, %w{<kilogram>},%w{<meter> <second> <second>}],
|
116
|
-
'<bar>' => [%w{bar bars}, 100000, :pressure, %w{<kilogram>},%w{<meter> <second> <second>}],
|
117
|
-
'<mmHg>' => [%w{mmHg}, 133.322368,:pressure, %w{<kilogram>},%w{<meter> <second> <second>}],
|
118
|
-
'<inHg>' => [%w{inHg}, 3386.3881472,:pressure, %w{<kilogram>},%w{<meter> <second> <second>}],
|
119
|
-
'<torr>' => [%w{torr}, 133.322368,:pressure, %w{<kilogram>},%w{<meter> <second> <second>}],
|
120
|
-
'<bar>' => [%w{bar}, 100000,:pressure, %w{<kilogram>},%w{<meter> <second> <second>}],
|
121
|
-
'<atm>' => [%w{atm ATM atmosphere atmospheres}, 101325,:pressure, %w{<kilogram>},%w{<meter> <second> <second>}],
|
122
|
-
'<psi>' => [%w{psi}, 6894.76,:pressure, %w{<kilogram>},%w{<meter> <second> <second>}],
|
123
|
-
'<cmh2o>' => [%w{cmH2O}, 98.0638,:pressure, %w{<kilogram>},%w{<meter> <second> <second>}],
|
124
|
-
'<inh2o>' => [%w{inH2O}, 249.082052,:pressure, %w{<kilogram>},%w{<meter> <second> <second>}],
|
125
|
-
|
126
|
-
#viscosity
|
127
|
-
'<poise>' => [%w{P poise}, 0.1, :viscosity, %w{<kilogram>},%w{<meter> <second>} ],
|
128
|
-
'<stokes>' => [%w{St stokes}, 1e-4, :viscosity, %w{<meter> <meter>}, %w{<second>}],
|
129
|
-
|
130
|
-
#substance
|
131
|
-
'<mole>' => [%w{mol mole}, 1.0, :substance, %w{<mole>}],
|
132
|
-
|
133
|
-
#concentration
|
134
|
-
'<molar>' => [%w{M molar}, 1000, :concentration, %w{<mole>}, %w{<meter> <meter> <meter>}],
|
135
|
-
'<wtpercent>' => [%w{wt% wtpercent}, 10, :concentration, %w{<kilogram>}, %w{<meter> <meter> <meter>}],
|
136
|
-
|
137
|
-
#activity
|
138
|
-
'<katal>' => [%w{kat katal Katal}, 1.0, :activity, %w{<mole>}, %w{<second>}],
|
139
|
-
'<unit>' => [%w{U enzUnit}, 16.667e-16, :activity, %w{<mole>}, %w{<second>}],
|
140
|
-
|
141
|
-
#capacitance
|
142
|
-
'<farad>' => [%w{F farad Farad}, 1.0, :capacitance, %w{<farad>}],
|
143
|
-
|
144
|
-
#charge
|
145
|
-
'<coulomb>' => [%w{C coulomb Coulomb}, 1.0, :charge, %w{<ampere> <second>}],
|
146
|
-
|
147
|
-
#current
|
148
|
-
'<ampere>' => [%w{A Ampere ampere amp amps}, 1.0, :current, %w{<ampere>}],
|
149
|
-
|
150
|
-
#conductance
|
151
|
-
'<siemens>' => [%w{S Siemens siemens}, 1.0, :resistance, %w{<second> <second> <second> <ampere> <ampere>}, %w{<kilogram> <meter> <meter>}],
|
152
|
-
|
153
|
-
#inductance
|
154
|
-
'<henry>' => [%w{H Henry henry}, 1.0, :inductance, %w{<meter> <meter> <kilogram>}, %w{<second> <second> <ampere> <ampere>}],
|
155
|
-
|
156
|
-
#potential
|
157
|
-
'<volt>' => [%w{V Volt volt volts}, 1.0, :potential, %w{<meter> <meter> <kilogram>}, %w{<second> <second> <second> <ampere>}],
|
158
|
-
|
159
|
-
#resistance
|
160
|
-
'<ohm>' => [%w{Ohm ohm}, 1.0, :resistance, %w{<meter> <meter> <kilogram>},%w{<second> <second> <second> <ampere> <ampere>}],
|
161
|
-
|
162
|
-
#magnetism
|
163
|
-
'<weber>' => [%w{Wb weber webers}, 1.0, :magnetism, %w{<meter> <meter> <kilogram>}, %w{<second> <second> <ampere>}],
|
164
|
-
'<tesla>' => [%w{T tesla teslas}, 1.0, :magnetism, %w{<kilogram>}, %w{<second> <second> <ampere>}],
|
165
|
-
'<gauss>' => [%w{G gauss}, 1e-4, :magnetism, %w{<kilogram>}, %w{<second> <second> <ampere>}],
|
166
|
-
'<maxwell>' => [%w{Mx maxwell maxwells}, 1e-8, :magnetism, %w{<meter> <meter> <kilogram>}, %w{<second> <second> <ampere>}],
|
167
|
-
'<oersted>' => [%w{Oe oersted oersteds}, 250.0/Math::PI, :magnetism, %w{<ampere>}, %w{<meter>}],
|
168
|
-
|
169
|
-
#energy
|
170
|
-
'<joule>' => [%w{J joule Joule joules}, 1.0, :energy, %w{<meter> <meter> <kilogram>}, %w{<second> <second>}],
|
171
|
-
'<erg>' => [%w{erg ergs}, 1e-7, :energy, %w{<meter> <meter> <kilogram>}, %w{<second> <second>}],
|
172
|
-
'<btu>' => [%w{BTU btu BTUs}, 1055.056, :energy, %w{<meter> <meter> <kilogram>}, %w{<second> <second>}],
|
173
|
-
'<calorie>' => [%w{cal calorie calories}, 4.18400, :energy,%w{<meter> <meter> <kilogram>}, %w{<second> <second>}],
|
174
|
-
'<Calorie>' => [%w{Cal Calorie Calories}, 4184.00, :energy,%w{<meter> <meter> <kilogram>}, %w{<second> <second>}],
|
175
|
-
'<therm-US>' => [%w{th therm therms Therm}, 105480400, :energy,%w{<meter> <meter> <kilogram>}, %w{<second> <second>}],
|
176
|
-
|
177
|
-
#force
|
178
|
-
'<newton>' => [%w{N Newton newton}, 1.0, :force, %w{<kilogram> <meter>}, %w{<second> <second>}],
|
179
|
-
'<dyne>' => [%w{dyn dyne}, 1e-5, :force, %w{<kilogram> <meter>}, %w{<second> <second>}],
|
180
|
-
'<pound-force>' => [%w{lbf pound-force}, 4.448222, :force, %w{<kilogram> <meter>}, %w{<second> <second>}],
|
181
|
-
|
182
|
-
#frequency
|
183
|
-
'<hertz>' => [%w{Hz hertz Hertz}, 1.0, :frequency, %w{<1>}, %{<second>}],
|
184
|
-
|
185
|
-
#angle
|
186
|
-
'<radian>' =>[%w{rad radian radian}, 1.0, :angle, %w{<radian>}],
|
187
|
-
'<degree>' =>[%w{deg degree degrees}, Math::PI / 180.0, :angle, %w{<radian>}],
|
188
|
-
'<grad>' =>[%w{grad gradian grads}, Math::PI / 200.0, :angle, %w{<radian>}],
|
189
|
-
'<steradian>' => [%w{sr steradian steradians}, 1.0, :solid_angle, %w{<steradian>}],
|
190
|
-
|
191
|
-
#rotation
|
192
|
-
'<rotation>' => [%w{rotation}, 2.0*Math::PI, :angle, %w{<radian>}],
|
193
|
-
'<rpm>' =>[%w{rpm}, 2.0*Math::PI / 60.0, :angular_velocity, %w{<radian>}, %w{<second>}],
|
194
|
-
|
195
|
-
#memory
|
196
|
-
'<byte>' =>[%w{B byte}, 1.0, :memory, %w{<byte>}],
|
197
|
-
'<bit>' =>[%w{b bit}, 0.125, :memory, %w{<byte>}],
|
198
|
-
|
199
|
-
#currency
|
200
|
-
'<dollar>'=>[%w{USD dollar}, 1.0, :currency, %w{<dollar>}],
|
201
|
-
'<cents>' =>[%w{cents}, 0.01, :currency, %w{<dollar>}],
|
202
|
-
|
203
|
-
#luminosity
|
204
|
-
'<candela>' => [%w{cd candela}, 1.0, :luminosity, %w{<candela>}],
|
205
|
-
'<lumen>' => [%w{lm lumen}, 1.0, :luminous_power, %w{<candela> <steradian>}],
|
206
|
-
'<lux>' =>[%w{lux}, 1.0, :illuminance, %w{<candela> <steradian>}, %w{<meter> <meter>}],
|
207
|
-
|
208
|
-
#power
|
209
|
-
'<watt>' => [%w{W watt watts}, 1.0, :power, %w{<kilogram> <meter> <meter>}, %w{<second> <second> <second>}],
|
210
|
-
'<horsepower>' => [%w{hp horsepower}, 745.699872, :power, %w{<kilogram> <meter> <meter>}, %w{<second> <second> <second>}],
|
211
|
-
|
212
|
-
#radiation
|
213
|
-
'<gray>' => [%w{Gy gray grays}, 1.0, :radiation, %w{<meter> <meter>}, %w{<second> <second>}],
|
214
|
-
'<roentgen>' => [%w{R roentgen}, 0.009330, :radiation, %w{<meter> <meter>}, %w{<second> <second>}],
|
215
|
-
'<sievert>' => [%w{Sv sievert sieverts}, 1.0, :radiation, %w{<meter> <meter>}, %w{<second> <second>}],
|
216
|
-
'<becquerel>' => [%w{Bq bequerel bequerels}, 1.0, :radiation, %w{<1>},%w{<second>}],
|
217
|
-
'<curie>' => [%w{Ci curie curies}, 3.7e10, :radiation, %w{<1>},%w{<second>}],
|
218
|
-
|
219
|
-
# rate
|
220
|
-
'<cpm>' => [%w{cpm}, 1.0/60.0, :rate, %w{<count>},%w{<second>}],
|
221
|
-
'<dpm>' => [%w{dpm}, 1.0/60.0, :rate, %w{<count>},%w{<second>}],
|
222
|
-
'<bpm>' => [%w{bpm}, 1.0/60.0, :rate, %w{<count>},%w{<second>}],
|
223
|
-
|
224
|
-
#resolution / typography
|
225
|
-
'<dot>' => [%w{dot dots}, 1, :resolution, %w{<each>}],
|
226
|
-
'<pixel>' => [%w{pixel px}, 1, :resolution, %w{<each>}],
|
227
|
-
'<ppi>' => [%w{ppi}, 1, :resolution, %w{<pixel>}, %w{<inch>}],
|
228
|
-
'<dpi>' => [%w{dpi}, 1, :typography, %w{<dot>}, %w{<inch>}],
|
229
|
-
'<pica>' => [%w{pica}, 0.00423333333 , :typography, %w{<meter>}],
|
230
|
-
'<point>' => [%w{point pt}, 0.000352777778, :typography, %w{<meter>}],
|
231
|
-
|
232
|
-
#other
|
233
|
-
'<cell>' => [%w{cells cell}, 1, :counting, %w{<each>}],
|
234
|
-
'<each>' => [%w{each}, 1.0, :counting, %w{<each>}],
|
235
|
-
'<count>' => [%w{count}, 1.0, :counting, %w{<each>}],
|
236
|
-
'<base-pair>' => [%w{bp}, 1.0, :counting, %w{<each>}],
|
237
|
-
'<nucleotide>' => [%w{nt}, 1.0, :counting, %w{<each>}],
|
238
|
-
'<molecule>' => [%w{molecule molecules}, 1.0, :counting, %w{<1>}],
|
239
|
-
'<dozen>' => [%w{doz dz dozen},12.0,:prefix_only, %w{<each>}],
|
240
|
-
'<percent>'=> [%w{% percent}, 0.01, :prefix_only, %w{<1>}],
|
241
|
-
'<ppm>' => [%w{ppm},1e-6,:prefix_only, %w{<1>}],
|
242
|
-
'<ppt>' => [%w{ppt},1e-9,:prefix_only, %w{<1>}],
|
243
|
-
'<gross>' => [%w{gr gross},144.0, :prefix_only, %w{<dozen> <dozen>}],
|
244
|
-
'<decibel>' => [%w{dB decibel decibels}, 1.0, :logarithmic, %w{<decibel>}]
|
245
|
-
|
246
|
-
|
247
|
-
} # doc
|
248
|
-
end
|
data/lib/ruby_units/version.rb
DELETED
data/ruby-units.gemspec
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in RakeFile, and run 'rake gemspec'
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = %q{ruby-units}
|
8
|
-
s.version = "1.2.0"
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Kevin Olbrich, Ph.D."]
|
12
|
-
s.date = %q{2011-04-01}
|
13
|
-
s.description = %q{Provides classes and methods to perform unit math and conversions}
|
14
|
-
s.email = ["kevin.olbrich+ruby_units@gmail.com"]
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE.txt",
|
17
|
-
"README.md",
|
18
|
-
"TODO"
|
19
|
-
]
|
20
|
-
s.files = [
|
21
|
-
"CHANGELOG.txt",
|
22
|
-
"Gemfile",
|
23
|
-
"LICENSE.txt",
|
24
|
-
"Manifest.txt",
|
25
|
-
"README.md",
|
26
|
-
"RakeFile",
|
27
|
-
"TODO",
|
28
|
-
"VERSION",
|
29
|
-
"lib/ruby-units.rb",
|
30
|
-
"lib/ruby_units.rb",
|
31
|
-
"lib/ruby_units/array.rb",
|
32
|
-
"lib/ruby_units/cmath.rb",
|
33
|
-
"lib/ruby_units/complex.rb",
|
34
|
-
"lib/ruby_units/date.rb",
|
35
|
-
"lib/ruby_units/math.rb",
|
36
|
-
"lib/ruby_units/numeric.rb",
|
37
|
-
"lib/ruby_units/object.rb",
|
38
|
-
"lib/ruby_units/ruby-units.rb",
|
39
|
-
"lib/ruby_units/string.rb",
|
40
|
-
"lib/ruby_units/time.rb",
|
41
|
-
"lib/ruby_units/units.rb",
|
42
|
-
"lib/ruby_units/version.rb",
|
43
|
-
"ruby-units.gemspec",
|
44
|
-
"test/test_ruby-units.rb"
|
45
|
-
]
|
46
|
-
s.homepage = %q{https://github.com/olbrich/ruby-units}
|
47
|
-
s.require_paths = ["lib"]
|
48
|
-
s.rubygems_version = %q{1.3.7}
|
49
|
-
s.summary = %q{A class that performs unit conversions and unit math}
|
50
|
-
s.test_files = [
|
51
|
-
"test/test_ruby-units.rb"
|
52
|
-
]
|
53
|
-
|
54
|
-
if s.respond_to? :specification_version then
|
55
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
56
|
-
s.specification_version = 3
|
57
|
-
|
58
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
59
|
-
s.add_development_dependency(%q<bundler>, ["~> 1.0"])
|
60
|
-
s.add_development_dependency(%q<rcov>, [">= 0"])
|
61
|
-
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
62
|
-
else
|
63
|
-
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
64
|
-
s.add_dependency(%q<rcov>, [">= 0"])
|
65
|
-
s.add_dependency(%q<jeweler>, [">= 0"])
|
66
|
-
end
|
67
|
-
else
|
68
|
-
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
69
|
-
s.add_dependency(%q<rcov>, [">= 0"])
|
70
|
-
s.add_dependency(%q<jeweler>, [">= 0"])
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|