ruby-units 1.4.2 → 1.4.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.txt +7 -0
- data/README.md +2 -2
- data/{RakeFile → Rakefile.rb} +0 -0
- data/VERSION +1 -1
- data/lib/ruby_units/time.rb +5 -7
- data/lib/ruby_units/unit.rb +52 -37
- data/ruby-units.gemspec +5 -20
- metadata +5 -85
data/CHANGELOG.txt
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
Change Log for Ruby-units
|
2
2
|
=========================
|
3
|
+
2013-06-11 1.4.3 * Fix issue #70 -- Support passing Time objects to Time.at
|
4
|
+
* Fix issue #72 -- Remove non-existent RakeFile from gemspec
|
5
|
+
* Fix issue #71 -- Fix YAML test failure
|
6
|
+
* Fix issue #49 -- Unit instances constructed using other Unit instances are incompatible within the framework
|
7
|
+
* Fix issue #61 -- Fix failing case of subtraction losing Units class
|
8
|
+
* Fix issue #63 -- fixes an issue with to_date on 1.8.7
|
9
|
+
* Fix issue #64 -- Aliases aren't considered in Unit.defined? method
|
3
10
|
2012-09-16 1.4.2 * Fix issue #54 -- pluralization of fluid-ounces
|
4
11
|
* Fix issue #53, 51 -- incorrect definition for gee
|
5
12
|
* Fix issue #52 -- add support for degree symbol
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Ruby Units
|
2
2
|
|
3
|
-
[![
|
3
|
+
[![Build Status](https://secure.travis-ci.org/olbrich/ruby-units.png)](http://travis-ci.org/olbrich/ruby-units)
|
4
4
|
|
5
5
|
Kevin C. Olbrich, Ph.D.
|
6
6
|
|
@@ -170,4 +170,4 @@ This is useful for changing display names, adding aliases, etc.
|
|
170
170
|
Unit.redefine!("cup") do |cup|
|
171
171
|
cup.display_name = "cup"
|
172
172
|
end
|
173
|
-
|
173
|
+
|
data/{RakeFile → Rakefile.rb}
RENAMED
File without changes
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.4.
|
1
|
+
1.4.3
|
data/lib/ruby_units/time.rb
CHANGED
@@ -16,6 +16,8 @@ class Time
|
|
16
16
|
# @return [Unit, Time]
|
17
17
|
def self.at(arg,ms=0)
|
18
18
|
case arg
|
19
|
+
when Time
|
20
|
+
unit_time_at(arg)
|
19
21
|
when Unit
|
20
22
|
unit_time_at(arg.convert_to("s").scalar, ms)
|
21
23
|
else
|
@@ -29,14 +31,10 @@ class Time
|
|
29
31
|
end
|
30
32
|
alias :unit :to_unit
|
31
33
|
alias :u :to_unit
|
32
|
-
|
33
|
-
unless Time.
|
34
|
+
|
35
|
+
unless Time.public_method_defined?(:to_date)
|
34
36
|
# :nocov_19:
|
35
|
-
|
36
|
-
def to_date
|
37
|
-
x=(Date.civil(1970,1,1)+((self.to_f+self.gmt_offset)/86400.0)-0.5)
|
38
|
-
Date.civil(x.year, x.month, x.day)
|
39
|
-
end
|
37
|
+
public :to_date
|
40
38
|
# :nocov_19:
|
41
39
|
end
|
42
40
|
|
data/lib/ruby_units/unit.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
require 'date'
|
2
3
|
if RUBY_VERSION < "1.9"
|
3
4
|
# :nocov_19:
|
@@ -150,7 +151,7 @@ class Unit < Numeric
|
|
150
151
|
# @param [String] unit
|
151
152
|
# @return [Boolean]
|
152
153
|
def self.defined?(unit)
|
153
|
-
|
154
|
+
self.definitions.values.any? {|d| d.aliases.include?(unit)}
|
154
155
|
end
|
155
156
|
|
156
157
|
# return the unit definition for a unit
|
@@ -249,7 +250,7 @@ class Unit < Numeric
|
|
249
250
|
end
|
250
251
|
|
251
252
|
# Used to copy one unit to another
|
252
|
-
# @param [Unit] from Unit to copy
|
253
|
+
# @param [Unit] from Unit to copy definition from
|
253
254
|
# @return [Unit]
|
254
255
|
def copy(from)
|
255
256
|
@scalar = from.scalar
|
@@ -312,7 +313,7 @@ class Unit < Numeric
|
|
312
313
|
@base_scalar = nil
|
313
314
|
@unit_name = nil
|
314
315
|
@signature = nil
|
315
|
-
@output = {}
|
316
|
+
@output = { }
|
316
317
|
raise ArgumentError, "Invalid Unit Format" if options[0].nil?
|
317
318
|
if options.size == 2
|
318
319
|
# options[0] is the scalar
|
@@ -338,31 +339,34 @@ class Unit < Numeric
|
|
338
339
|
end
|
339
340
|
|
340
341
|
case options[0]
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
342
|
+
when Unit
|
343
|
+
copy(options[0])
|
344
|
+
return
|
345
|
+
when Hash
|
346
|
+
@scalar = options[0][:scalar] || 1
|
347
|
+
@numerator = options[0][:numerator] || UNITY_ARRAY
|
348
|
+
@denominator = options[0][:denominator] || UNITY_ARRAY
|
349
|
+
@signature = options[0][:signature]
|
350
|
+
when Array
|
351
|
+
initialize(*options[0])
|
352
|
+
return
|
353
|
+
when Numeric
|
354
|
+
@scalar = options[0]
|
355
|
+
@numerator = @denominator = UNITY_ARRAY
|
356
|
+
when Time
|
357
|
+
@scalar = options[0].to_f
|
358
|
+
@numerator = ['<second>']
|
359
|
+
@denominator = UNITY_ARRAY
|
360
|
+
when DateTime, Date
|
361
|
+
@scalar = options[0].ajd
|
362
|
+
@numerator = ['<day>']
|
363
|
+
@denominator = UNITY_ARRAY
|
364
|
+
when /^\s*$/
|
365
|
+
raise ArgumentError, "No Unit Specified"
|
366
|
+
when String
|
367
|
+
parse(options[0])
|
368
|
+
else
|
369
|
+
raise ArgumentError, "Invalid Unit Format"
|
366
370
|
end
|
367
371
|
self.update_base_scalar
|
368
372
|
raise ArgumentError, "Temperatures must not be less than absolute zero" if self.is_temperature? && self.base_scalar < 0
|
@@ -733,7 +737,11 @@ class Unit < Numeric
|
|
733
737
|
when Unit
|
734
738
|
case
|
735
739
|
when self.zero?
|
736
|
-
|
740
|
+
if other.zero?
|
741
|
+
other.dup * -1 # preserve Units class
|
742
|
+
else
|
743
|
+
-other.dup
|
744
|
+
end
|
737
745
|
when self =~ other
|
738
746
|
case
|
739
747
|
when [self, other].all? {|x| x.is_temperature?}
|
@@ -1102,10 +1110,18 @@ class Unit < Numeric
|
|
1102
1110
|
return Unit.new(@scalar.floor, @numerator, @denominator)
|
1103
1111
|
end
|
1104
1112
|
|
1105
|
-
|
1106
|
-
|
1107
|
-
|
1108
|
-
|
1113
|
+
if RUBY_VERSION < '1.9'
|
1114
|
+
# @return [Numeric,Unit]
|
1115
|
+
def round
|
1116
|
+
return @scalar.round if self.unitless?
|
1117
|
+
return Unit.new(@scalar.round, @numerator, @denominator)
|
1118
|
+
end
|
1119
|
+
else
|
1120
|
+
# @return [Numeric,Unit]
|
1121
|
+
def round(ndigits = 0)
|
1122
|
+
return @scalar.round(ndigits) if self.unitless?
|
1123
|
+
return Unit.new(@scalar.round(ndigits), @numerator, @denominator)
|
1124
|
+
end
|
1109
1125
|
end
|
1110
1126
|
|
1111
1127
|
# @return [Numeric, Unit]
|
@@ -1367,8 +1383,7 @@ class Unit < Numeric
|
|
1367
1383
|
if unit_string =~ /\$\s*(#{NUMBER_REGEX})/
|
1368
1384
|
unit_string = "#{$1} USD"
|
1369
1385
|
end
|
1370
|
-
|
1371
|
-
unit_string.gsub!("\xC2\xB0".force_encoding('utf-8'), 'deg') unless RUBY_VERSION < '1.9'
|
1386
|
+
unit_string.gsub!("\u00b0".force_encoding('utf-8'), 'deg') if RUBY_VERSION >= '1.9' && unit_string.encoding == Encoding::UTF_8
|
1372
1387
|
|
1373
1388
|
unit_string.gsub!(/%/,'percent')
|
1374
1389
|
unit_string.gsub!(/'/,'feet')
|
@@ -1572,5 +1587,5 @@ class Unit < Numeric
|
|
1572
1587
|
@@UNIT_REGEX = nil #invalidate the unit regex
|
1573
1588
|
end
|
1574
1589
|
end
|
1575
|
-
|
1576
|
-
end
|
1590
|
+
|
1591
|
+
end
|
data/ruby-units.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile.rb, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "ruby-units"
|
8
|
-
s.version = "1.4.
|
8
|
+
s.version = "1.4.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kevin Olbrich, Ph.D."]
|
12
|
-
s.date = "
|
12
|
+
s.date = "2013-06-12"
|
13
13
|
s.description = "Provides classes and methods to perform unit math and conversions"
|
14
14
|
s.email = ["kevin.olbrich+ruby_units@gmail.com"]
|
15
15
|
s.extra_rdoc_files = [
|
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
|
|
21
21
|
"CHANGELOG.txt",
|
22
22
|
"LICENSE.txt",
|
23
23
|
"README.md",
|
24
|
-
"
|
24
|
+
"Rakefile.rb",
|
25
25
|
"TODO",
|
26
26
|
"VERSION",
|
27
27
|
"lib/ruby-units.rb",
|
@@ -48,7 +48,7 @@ Gem::Specification.new do |s|
|
|
48
48
|
s.licenses = ["MIT"]
|
49
49
|
s.post_install_message = "====================\nDeprecation Warning\n====================\n\nSeveral convenience methods that ruby-units added to the string class have\nbeen deprecated in this release. These methods include String#to, String#from, String#ago, String#before and others.\nIf your code relies on these functions, they can be added back by adding this line to your code.\n\nrequire 'ruby-units/string/extras'\n# note that these methods do not play well with Rails, which is one of the reasons they are being removed.\n\nThe extra functions mostly work the same, but will no longer properly handle cases when they are called with strings..\n\n'min'.from(\"4-1-2011\") # => Exception\n\nPass in a Date, Time, or DateTime object to get the expected result.\n\nThey will go away completely in the next release, so it would be a good idea to refactor your code\nto avoid using them. They will also throw deprecation warnings when they are used.\n"
|
50
50
|
s.require_paths = ["lib"]
|
51
|
-
s.rubygems_version = "1.8.
|
51
|
+
s.rubygems_version = "1.8.25"
|
52
52
|
s.summary = "A class that performs unit conversions and unit math"
|
53
53
|
|
54
54
|
if s.respond_to? :specification_version then
|
@@ -56,29 +56,14 @@ Gem::Specification.new do |s|
|
|
56
56
|
|
57
57
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
58
58
|
s.add_development_dependency(%q<bundler>, ["~> 1.0"])
|
59
|
-
s.add_development_dependency(%q<rcov>, [">= 0"])
|
60
|
-
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
61
|
-
s.add_development_dependency(%q<simplecov-html>, [">= 0"])
|
62
59
|
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
63
|
-
s.add_development_dependency(%q<rspec>, ["~> 2.5"])
|
64
|
-
s.add_development_dependency(%q<autotest>, [">= 0"])
|
65
60
|
else
|
66
61
|
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
67
|
-
s.add_dependency(%q<rcov>, [">= 0"])
|
68
|
-
s.add_dependency(%q<simplecov>, [">= 0"])
|
69
|
-
s.add_dependency(%q<simplecov-html>, [">= 0"])
|
70
62
|
s.add_dependency(%q<jeweler>, [">= 0"])
|
71
|
-
s.add_dependency(%q<rspec>, ["~> 2.5"])
|
72
|
-
s.add_dependency(%q<autotest>, [">= 0"])
|
73
63
|
end
|
74
64
|
else
|
75
65
|
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
76
|
-
s.add_dependency(%q<rcov>, [">= 0"])
|
77
|
-
s.add_dependency(%q<simplecov>, [">= 0"])
|
78
|
-
s.add_dependency(%q<simplecov-html>, [">= 0"])
|
79
66
|
s.add_dependency(%q<jeweler>, [">= 0"])
|
80
|
-
s.add_dependency(%q<rspec>, ["~> 2.5"])
|
81
|
-
s.add_dependency(%q<autotest>, [">= 0"])
|
82
67
|
end
|
83
68
|
end
|
84
69
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-units
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-06-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -27,54 +27,6 @@ dependencies:
|
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '1.0'
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
name: rcov
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
|
-
requirements:
|
35
|
-
- - ! '>='
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: '0'
|
38
|
-
type: :development
|
39
|
-
prerelease: false
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ! '>='
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: '0'
|
46
|
-
- !ruby/object:Gem::Dependency
|
47
|
-
name: simplecov
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
|
-
requirements:
|
51
|
-
- - ! '>='
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '0'
|
54
|
-
type: :development
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
|
-
requirements:
|
59
|
-
- - ! '>='
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
- !ruby/object:Gem::Dependency
|
63
|
-
name: simplecov-html
|
64
|
-
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
|
-
requirements:
|
67
|
-
- - ! '>='
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: '0'
|
70
|
-
type: :development
|
71
|
-
prerelease: false
|
72
|
-
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
|
-
requirements:
|
75
|
-
- - ! '>='
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version: '0'
|
78
30
|
- !ruby/object:Gem::Dependency
|
79
31
|
name: jeweler
|
80
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -91,38 +43,6 @@ dependencies:
|
|
91
43
|
- - ! '>='
|
92
44
|
- !ruby/object:Gem::Version
|
93
45
|
version: '0'
|
94
|
-
- !ruby/object:Gem::Dependency
|
95
|
-
name: rspec
|
96
|
-
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
|
-
requirements:
|
99
|
-
- - ~>
|
100
|
-
- !ruby/object:Gem::Version
|
101
|
-
version: '2.5'
|
102
|
-
type: :development
|
103
|
-
prerelease: false
|
104
|
-
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
|
-
requirements:
|
107
|
-
- - ~>
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version: '2.5'
|
110
|
-
- !ruby/object:Gem::Dependency
|
111
|
-
name: autotest
|
112
|
-
requirement: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
|
-
requirements:
|
115
|
-
- - ! '>='
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
none: false
|
122
|
-
requirements:
|
123
|
-
- - ! '>='
|
124
|
-
- !ruby/object:Gem::Version
|
125
|
-
version: '0'
|
126
46
|
description: Provides classes and methods to perform unit math and conversions
|
127
47
|
email:
|
128
48
|
- kevin.olbrich+ruby_units@gmail.com
|
@@ -136,7 +56,7 @@ files:
|
|
136
56
|
- CHANGELOG.txt
|
137
57
|
- LICENSE.txt
|
138
58
|
- README.md
|
139
|
-
-
|
59
|
+
- Rakefile.rb
|
140
60
|
- TODO
|
141
61
|
- VERSION
|
142
62
|
- lib/ruby-units.rb
|
@@ -210,7 +130,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
210
130
|
version: '0'
|
211
131
|
segments:
|
212
132
|
- 0
|
213
|
-
hash: -
|
133
|
+
hash: -240639428179076096
|
214
134
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
215
135
|
none: false
|
216
136
|
requirements:
|
@@ -219,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
219
139
|
version: '0'
|
220
140
|
requirements: []
|
221
141
|
rubyforge_project:
|
222
|
-
rubygems_version: 1.8.
|
142
|
+
rubygems_version: 1.8.25
|
223
143
|
signing_key:
|
224
144
|
specification_version: 3
|
225
145
|
summary: A class that performs unit conversions and unit math
|