ruby-units 2.4.1 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/codeql-analysis.yml +3 -3
- data/.github/workflows/tests.yml +3 -1
- data/.rubocop.yml +2 -0
- data/.ruby-version +1 -1
- data/.solargraph.yml +1 -1
- data/.tool-versions +2 -0
- data/CHANGELOG.txt +3 -1
- data/Gemfile +16 -1
- data/Gemfile.lock +91 -66
- data/README.md +2 -0
- data/lib/ruby_units/array.rb +17 -7
- data/lib/ruby_units/cache.rb +27 -14
- data/lib/ruby_units/configuration.rb +8 -8
- data/lib/ruby_units/date.rb +46 -53
- data/lib/ruby_units/math.rb +136 -113
- data/lib/ruby_units/numeric.rb +21 -5
- data/lib/ruby_units/string.rb +34 -21
- data/lib/ruby_units/time.rb +76 -69
- data/lib/ruby_units/unit.rb +442 -340
- data/lib/ruby_units/version.rb +1 -1
- data/ruby-units.gemspec +2 -14
- metadata +8 -175
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 572cf98377411ff41dd490f784564f3b50401a7342552a7999688ea0763eec5b
|
4
|
+
data.tar.gz: 735696cb4410be7d1d7a1d03fabaa4fa734a2dc6f5c4a8a37648dcd88a461168
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0d994f5f9a10375fad35fa00905dc23ae5227e08157f10f27c85955e1d0df98500bb6d1174298b9f95f02a4f568a6d363af21204f6564e1c28f8b19c44a229f
|
7
|
+
data.tar.gz: 491e25dbb90dc0e7f5829b46c4973b178a49119ed3343fc6fe9931131d08525b0e8655079a6321bbbfef4f3624c0746dbbfde5b9dc866828fbe1a97d691b9569
|
@@ -42,7 +42,7 @@ jobs:
|
|
42
42
|
|
43
43
|
# Initializes the CodeQL tools for scanning.
|
44
44
|
- name: Initialize CodeQL
|
45
|
-
uses: github/codeql-action/init@
|
45
|
+
uses: github/codeql-action/init@v2
|
46
46
|
with:
|
47
47
|
languages: ${{ matrix.language }}
|
48
48
|
# If you wish to specify custom queries, you can do so here or in a config file.
|
@@ -53,7 +53,7 @@ jobs:
|
|
53
53
|
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
54
54
|
# If this step fails, then you should remove it and run the build manually (see below)
|
55
55
|
- name: Autobuild
|
56
|
-
uses: github/codeql-action/autobuild@
|
56
|
+
uses: github/codeql-action/autobuild@v2
|
57
57
|
|
58
58
|
# ℹ️ Command-line programs to run using the OS shell.
|
59
59
|
# 📚 https://git.io/JvXDl
|
@@ -67,4 +67,4 @@ jobs:
|
|
67
67
|
# make release
|
68
68
|
|
69
69
|
- name: Perform CodeQL Analysis
|
70
|
-
uses: github/codeql-action/analyze@
|
70
|
+
uses: github/codeql-action/analyze@v2
|
data/.github/workflows/tests.yml
CHANGED
@@ -15,7 +15,9 @@ jobs:
|
|
15
15
|
strategy:
|
16
16
|
fail-fast: false
|
17
17
|
matrix:
|
18
|
-
ruby: ['
|
18
|
+
ruby: ['3.0', '3.1', '3.2', '3.3', 'jruby-9.4']
|
19
|
+
env:
|
20
|
+
BUNDLE_WITHOUT: optional
|
19
21
|
steps:
|
20
22
|
- uses: actions/checkout@v2
|
21
23
|
- uses: ruby/setup-ruby@v1
|
data/.rubocop.yml
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
3.0.6
|
data/.solargraph.yml
CHANGED
data/.tool-versions
ADDED
data/CHANGELOG.txt
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
Change Log for Ruby-units
|
2
2
|
=========================
|
3
|
-
|
3
|
+
|
4
|
+
see GitHub releases (https://github.com/olbrich/ruby-units/releases) for more recent releases. This file will no longer
|
5
|
+
be updated.
|
4
6
|
|
5
7
|
2020-12-29 2.3.2 * Remove Jeweler (see #178) also adds Code of Conduct
|
6
8
|
* Fix specs related to Complex comparisons (see #213)
|
data/Gemfile
CHANGED
@@ -1,10 +1,25 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
|
3
|
+
# These are gems that are only used for local development and don't need to be included at runtime or for running tests.
|
4
|
+
# The CI process will not install them.
|
5
|
+
group :optional do
|
4
6
|
gem 'debug', '>= 1.0.0', platform: :mri
|
7
|
+
gem 'guard-rspec'
|
8
|
+
gem 'pry'
|
5
9
|
gem 'redcarpet', platform: :mri # redcarpet doesn't support jruby
|
10
|
+
gem 'rubocop'
|
11
|
+
gem 'rubocop-rake'
|
12
|
+
gem 'rubocop-rspec'
|
6
13
|
gem 'ruby-maven', platform: :jruby
|
7
14
|
gem 'ruby-prof', platform: :mri
|
15
|
+
gem 'simplecov-html'
|
16
|
+
gem 'solargraph'
|
17
|
+
gem 'terminal-notifier'
|
18
|
+
gem 'terminal-notifier-guard'
|
19
|
+
gem 'webrick'
|
20
|
+
gem 'yard'
|
8
21
|
end
|
9
22
|
|
23
|
+
gem 'simplecov'
|
24
|
+
|
10
25
|
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,25 +1,26 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ruby-units (
|
4
|
+
ruby-units (4.0.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
9
|
ast (2.4.2)
|
10
10
|
backport (1.2.0)
|
11
|
-
|
11
|
+
base64 (0.1.1)
|
12
|
+
benchmark (0.2.1)
|
12
13
|
coderay (1.1.3)
|
13
|
-
debug (1.
|
14
|
-
irb (>= 1.
|
14
|
+
debug (1.8.0)
|
15
|
+
irb (>= 1.5.0)
|
15
16
|
reline (>= 0.3.1)
|
16
17
|
diff-lcs (1.5.0)
|
17
18
|
docile (1.4.0)
|
18
19
|
e2mmap (0.1.0)
|
19
|
-
ffi (1.
|
20
|
-
ffi (1.
|
20
|
+
ffi (1.16.1)
|
21
|
+
ffi (1.16.1-java)
|
21
22
|
formatador (1.1.0)
|
22
|
-
guard (2.18.
|
23
|
+
guard (2.18.1)
|
23
24
|
formatador (>= 0.2.4)
|
24
25
|
listen (>= 2.7, < 4.0)
|
25
26
|
lumberjack (>= 1.0.12, < 2.0)
|
@@ -33,130 +34,154 @@ GEM
|
|
33
34
|
guard (~> 2.1)
|
34
35
|
guard-compat (~> 1.1)
|
35
36
|
rspec (>= 2.99.0, < 4.0)
|
36
|
-
io-console (0.
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
37
|
+
io-console (0.6.0)
|
38
|
+
io-console (0.6.0-java)
|
39
|
+
irb (1.8.1)
|
40
|
+
rdoc
|
41
|
+
reline (>= 0.3.8)
|
42
|
+
jar-dependencies (0.4.1)
|
43
|
+
jaro_winkler (1.5.6)
|
44
|
+
jaro_winkler (1.5.6-java)
|
45
|
+
json (2.6.3)
|
46
|
+
json (2.6.3-java)
|
43
47
|
kramdown (2.4.0)
|
44
48
|
rexml
|
45
49
|
kramdown-parser-gfm (1.1.0)
|
46
50
|
kramdown (~> 2.0)
|
47
|
-
|
51
|
+
language_server-protocol (3.17.0.3)
|
52
|
+
listen (3.8.0)
|
48
53
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
49
54
|
rb-inotify (~> 0.9, >= 0.9.10)
|
50
|
-
lumberjack (1.2.
|
55
|
+
lumberjack (1.2.9)
|
51
56
|
method_source (1.0.0)
|
52
|
-
mini_portile2 (2.8.0)
|
53
57
|
nenv (0.3.0)
|
54
|
-
nokogiri (1.
|
55
|
-
mini_portile2 (~> 2.8.0)
|
58
|
+
nokogiri (1.15.4-arm64-darwin)
|
56
59
|
racc (~> 1.4)
|
57
|
-
nokogiri (1.
|
60
|
+
nokogiri (1.15.4-java)
|
58
61
|
racc (~> 1.4)
|
59
|
-
nokogiri (1.
|
62
|
+
nokogiri (1.15.4-x86_64-darwin)
|
63
|
+
racc (~> 1.4)
|
64
|
+
nokogiri (1.15.4-x86_64-linux)
|
60
65
|
racc (~> 1.4)
|
61
66
|
notiffany (0.1.3)
|
62
67
|
nenv (~> 0.1)
|
63
68
|
shellany (~> 0.0)
|
64
|
-
parallel (1.
|
65
|
-
parser (3.
|
69
|
+
parallel (1.23.0)
|
70
|
+
parser (3.2.2.3)
|
66
71
|
ast (~> 2.4.1)
|
67
|
-
|
72
|
+
racc
|
73
|
+
pry (0.14.2)
|
68
74
|
coderay (~> 1.1)
|
69
75
|
method_source (~> 1.0)
|
70
|
-
pry (0.14.
|
76
|
+
pry (0.14.2-java)
|
71
77
|
coderay (~> 1.1)
|
72
78
|
method_source (~> 1.0)
|
73
79
|
spoon (~> 0.0)
|
74
|
-
|
75
|
-
|
80
|
+
psych (5.1.0)
|
81
|
+
stringio
|
82
|
+
psych (5.1.0-java)
|
83
|
+
jar-dependencies (>= 0.1.7)
|
84
|
+
racc (1.7.1)
|
85
|
+
racc (1.7.1-java)
|
76
86
|
rainbow (3.1.1)
|
77
87
|
rake (13.0.6)
|
78
|
-
rb-fsevent (0.11.
|
88
|
+
rb-fsevent (0.11.2)
|
79
89
|
rb-inotify (0.10.1)
|
80
90
|
ffi (~> 1.0)
|
81
|
-
|
82
|
-
|
83
|
-
|
91
|
+
rbs (2.8.4)
|
92
|
+
rdoc (6.5.0)
|
93
|
+
psych (>= 4.0.0)
|
94
|
+
redcarpet (3.6.0)
|
95
|
+
regexp_parser (2.8.1)
|
96
|
+
reline (0.3.8)
|
84
97
|
io-console (~> 0.5)
|
85
98
|
reverse_markdown (2.1.1)
|
86
99
|
nokogiri
|
87
|
-
rexml (3.2.
|
88
|
-
rspec (3.
|
89
|
-
rspec-core (~> 3.
|
90
|
-
rspec-expectations (~> 3.
|
91
|
-
rspec-mocks (~> 3.
|
92
|
-
rspec-core (3.
|
93
|
-
rspec-support (~> 3.
|
94
|
-
rspec-expectations (3.
|
100
|
+
rexml (3.2.6)
|
101
|
+
rspec (3.12.0)
|
102
|
+
rspec-core (~> 3.12.0)
|
103
|
+
rspec-expectations (~> 3.12.0)
|
104
|
+
rspec-mocks (~> 3.12.0)
|
105
|
+
rspec-core (3.12.2)
|
106
|
+
rspec-support (~> 3.12.0)
|
107
|
+
rspec-expectations (3.12.3)
|
95
108
|
diff-lcs (>= 1.2.0, < 2.0)
|
96
|
-
rspec-support (~> 3.
|
97
|
-
rspec-mocks (3.
|
109
|
+
rspec-support (~> 3.12.0)
|
110
|
+
rspec-mocks (3.12.6)
|
98
111
|
diff-lcs (>= 1.2.0, < 2.0)
|
99
|
-
rspec-support (~> 3.
|
100
|
-
rspec-support (3.
|
101
|
-
rubocop (1.
|
112
|
+
rspec-support (~> 3.12.0)
|
113
|
+
rspec-support (3.12.1)
|
114
|
+
rubocop (1.56.4)
|
115
|
+
base64 (~> 0.1.1)
|
102
116
|
json (~> 2.3)
|
117
|
+
language_server-protocol (>= 3.17.0)
|
103
118
|
parallel (~> 1.10)
|
104
|
-
parser (>= 3.
|
119
|
+
parser (>= 3.2.2.3)
|
105
120
|
rainbow (>= 2.2.2, < 4.0)
|
106
121
|
regexp_parser (>= 1.8, < 3.0)
|
107
122
|
rexml (>= 3.2.5, < 4.0)
|
108
|
-
rubocop-ast (>= 1.
|
123
|
+
rubocop-ast (>= 1.28.1, < 2.0)
|
109
124
|
ruby-progressbar (~> 1.7)
|
110
|
-
unicode-display_width (>=
|
111
|
-
rubocop-ast (1.
|
112
|
-
parser (>= 3.
|
125
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
126
|
+
rubocop-ast (1.29.0)
|
127
|
+
parser (>= 3.2.1.0)
|
128
|
+
rubocop-capybara (2.19.0)
|
129
|
+
rubocop (~> 1.41)
|
130
|
+
rubocop-factory_bot (2.24.0)
|
131
|
+
rubocop (~> 1.33)
|
113
132
|
rubocop-rake (0.6.0)
|
114
133
|
rubocop (~> 1.0)
|
115
|
-
rubocop-rspec (2.
|
116
|
-
rubocop (~> 1.
|
134
|
+
rubocop-rspec (2.24.1)
|
135
|
+
rubocop (~> 1.33)
|
136
|
+
rubocop-capybara (~> 2.17)
|
137
|
+
rubocop-factory_bot (~> 2.22)
|
117
138
|
ruby-maven (3.3.13)
|
118
139
|
ruby-maven-libs (~> 3.3.9)
|
119
140
|
ruby-maven-libs (3.3.9)
|
120
|
-
ruby-prof (1.
|
121
|
-
ruby-progressbar (1.
|
141
|
+
ruby-prof (1.6.3)
|
142
|
+
ruby-progressbar (1.13.0)
|
122
143
|
shellany (0.0.1)
|
123
|
-
simplecov (0.
|
144
|
+
simplecov (0.22.0)
|
124
145
|
docile (~> 1.1)
|
125
146
|
simplecov-html (~> 0.11)
|
126
147
|
simplecov_json_formatter (~> 0.1)
|
127
148
|
simplecov-html (0.12.3)
|
128
149
|
simplecov_json_formatter (0.1.4)
|
129
|
-
solargraph (0.
|
150
|
+
solargraph (0.49.0)
|
130
151
|
backport (~> 1.2)
|
131
152
|
benchmark
|
132
|
-
bundler (
|
153
|
+
bundler (~> 2.0)
|
133
154
|
diff-lcs (~> 1.4)
|
134
155
|
e2mmap
|
135
156
|
jaro_winkler (~> 1.5)
|
136
157
|
kramdown (~> 2.3)
|
137
158
|
kramdown-parser-gfm (~> 1.1)
|
138
159
|
parser (~> 3.0)
|
139
|
-
|
140
|
-
|
160
|
+
rbs (~> 2.0)
|
161
|
+
reverse_markdown (~> 2.0)
|
162
|
+
rubocop (~> 1.38)
|
141
163
|
thor (~> 1.0)
|
142
164
|
tilt (~> 2.0)
|
143
165
|
yard (~> 0.9, >= 0.9.24)
|
144
166
|
spoon (0.0.6)
|
145
167
|
ffi
|
168
|
+
stringio (3.0.8)
|
146
169
|
terminal-notifier (2.0.0)
|
147
170
|
terminal-notifier-guard (1.7.0)
|
148
|
-
thor (1.2.
|
149
|
-
tilt (2.0
|
150
|
-
unicode-display_width (2.
|
151
|
-
webrick (1.
|
152
|
-
yard (0.9.
|
153
|
-
webrick (~> 1.7.0)
|
171
|
+
thor (1.2.2)
|
172
|
+
tilt (2.3.0)
|
173
|
+
unicode-display_width (2.5.0)
|
174
|
+
webrick (1.8.1)
|
175
|
+
yard (0.9.34)
|
154
176
|
|
155
177
|
PLATFORMS
|
178
|
+
arm64-darwin-21
|
179
|
+
arm64-darwin-22
|
156
180
|
java
|
157
|
-
ruby
|
158
181
|
universal-java-11
|
182
|
+
universal-java-18
|
159
183
|
x86_64-darwin-19
|
184
|
+
x86_64-linux
|
160
185
|
|
161
186
|
DEPENDENCIES
|
162
187
|
debug (>= 1.0.0)
|
@@ -180,4 +205,4 @@ DEPENDENCIES
|
|
180
205
|
yard
|
181
206
|
|
182
207
|
BUNDLED WITH
|
183
|
-
2.
|
208
|
+
2.4.19
|
data/README.md
CHANGED
@@ -131,6 +131,8 @@ The `to_s` also accepts some options.
|
|
131
131
|
```ruby
|
132
132
|
Unit.new('1.5 mm').to_s("%0.2f") # "1.50 mm". Enter any valid format
|
133
133
|
# string. Also accepts strftime format
|
134
|
+
Unit.new('10 mm').to_s("%0.2f in")# "0.39 in". can also format and convert in
|
135
|
+
# the same time.
|
134
136
|
Unit.new('1.5 mm').to_s("in") # converts to inches before printing
|
135
137
|
Unit.new("2 m").to_s(:ft) # returns 6'7"
|
136
138
|
Unit.new("100 kg").to_s(:lbs) # returns 220 lbs, 7 oz
|
data/lib/ruby_units/array.rb
CHANGED
@@ -1,9 +1,19 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
module RubyUnits
|
2
|
+
# Extra methods for [::Array] to support conversion to [RubyUnits::Unit]
|
3
|
+
module Array
|
4
|
+
# Construct a unit from an array
|
5
|
+
#
|
6
|
+
# @example [1, 'mm'].to_unit => RubyUnits::Unit.new("1 mm")
|
7
|
+
# @param [RubyUnits::Unit, String] other convert to same units as passed
|
8
|
+
# @return [RubyUnits::Unit]
|
9
|
+
def to_unit(other = nil)
|
10
|
+
other ? RubyUnits::Unit.new(self).convert_to(other) : RubyUnits::Unit.new(self)
|
11
|
+
end
|
8
12
|
end
|
9
13
|
end
|
14
|
+
|
15
|
+
# @note Do this instead of Array.prepend(RubyUnits::Array) to avoid YARD warnings
|
16
|
+
# @see https://github.com/lsegal/yard/issues/1353
|
17
|
+
class Array
|
18
|
+
prepend(RubyUnits::Array)
|
19
|
+
end
|
data/lib/ruby_units/cache.rb
CHANGED
@@ -1,21 +1,34 @@
|
|
1
1
|
module RubyUnits
|
2
|
-
|
3
|
-
|
2
|
+
# Performance optimizations to avoid creating units unnecessarily
|
3
|
+
class Cache
|
4
|
+
attr_accessor :data
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
def initialize
|
7
|
+
clear
|
8
|
+
end
|
9
|
+
|
10
|
+
# @param key [String, #to_unit]
|
11
|
+
# @return [RubyUnits::Unit, nil]
|
12
|
+
def get(key)
|
13
|
+
key = key&.to_unit&.units unless key.is_a?(String)
|
14
|
+
data[key]
|
15
|
+
end
|
9
16
|
|
10
|
-
|
11
|
-
|
12
|
-
|
17
|
+
# @param key [String, #to_unit]
|
18
|
+
# @return [void]
|
19
|
+
def set(key, value)
|
20
|
+
key = key.to_unit.units unless key.is_a?(String)
|
21
|
+
data[key] = value
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [Array<String>]
|
25
|
+
def keys
|
26
|
+
data.keys
|
27
|
+
end
|
13
28
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
Unit.new(1)
|
18
|
-
end
|
29
|
+
# Reset the cache
|
30
|
+
def clear
|
31
|
+
@data = {}
|
19
32
|
end
|
20
33
|
end
|
21
34
|
end
|
@@ -1,10 +1,3 @@
|
|
1
|
-
# allow for optional configuration of RubyUnits
|
2
|
-
#
|
3
|
-
# Usage:
|
4
|
-
#
|
5
|
-
# RubyUnits.configure do |config|
|
6
|
-
# config.separator = false
|
7
|
-
# end
|
8
1
|
module RubyUnits
|
9
2
|
class << self
|
10
3
|
attr_writer :configuration
|
@@ -18,6 +11,13 @@ module RubyUnits
|
|
18
11
|
@configuration = Configuration.new
|
19
12
|
end
|
20
13
|
|
14
|
+
# allow for optional configuration of RubyUnits
|
15
|
+
#
|
16
|
+
# Usage:
|
17
|
+
#
|
18
|
+
# RubyUnits.configure do |config|
|
19
|
+
# config.separator = false
|
20
|
+
# end
|
21
21
|
def self.configure
|
22
22
|
yield configuration
|
23
23
|
end
|
@@ -34,7 +34,7 @@ module RubyUnits
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def separator=(value)
|
37
|
-
raise ArgumentError, "configuration 'separator' may only be true or false" unless
|
37
|
+
raise ArgumentError, "configuration 'separator' may only be true or false" unless [true, false].include?(value)
|
38
38
|
|
39
39
|
@separator = value ? ' ' : nil
|
40
40
|
end
|
data/lib/ruby_units/date.rb
CHANGED
@@ -1,64 +1,57 @@
|
|
1
1
|
require 'date'
|
2
2
|
|
3
|
-
|
4
|
-
# Date
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
3
|
+
module RubyUnits
|
4
|
+
# Extra methods for [::Date] to allow it to be used as a [RubyUnits::Unit]
|
5
|
+
module Date
|
6
|
+
# Allow date objects to do offsets by a time unit
|
7
|
+
#
|
8
|
+
# @example Date.today + Unit.new("1 week") => gives today+1 week
|
9
|
+
# @param [RubyUnits::Unit, Object] other
|
10
|
+
# @return [RubyUnits::Unit]
|
11
|
+
def +(other)
|
12
|
+
case other
|
13
|
+
when RubyUnits::Unit
|
14
|
+
other = other.convert_to('d').round if %w[y decade century].include? other.units
|
15
|
+
super(other.convert_to('day').scalar)
|
16
|
+
else
|
17
|
+
super
|
18
|
+
end
|
16
19
|
end
|
17
|
-
end
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
21
|
+
# Allow date objects to do offsets by a time unit
|
22
|
+
#
|
23
|
+
# @example Date.today - Unit.new("1 week") => gives today-1 week
|
24
|
+
# @param [RubyUnits::Unit, Object] other
|
25
|
+
# @return [RubyUnits::Unit]
|
26
|
+
def -(other)
|
27
|
+
case other
|
28
|
+
when RubyUnits::Unit
|
29
|
+
other = other.convert_to('d').round if %w[y decade century].include? other.units
|
30
|
+
super(other.convert_to('day').scalar)
|
31
|
+
else
|
32
|
+
super
|
33
|
+
end
|
29
34
|
end
|
30
|
-
end
|
31
35
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
other
|
38
|
-
|
39
|
-
|
40
|
-
# :nocov_19:
|
41
|
-
unless Date.instance_methods.include?(:to_time)
|
42
|
-
# @return [Time]
|
43
|
-
def to_time
|
44
|
-
Time.local(*ParseDate.parsedate(to_s))
|
36
|
+
# Construct a unit from a Date. This returns the number of days since the
|
37
|
+
# start of the Julian calendar as a Unit.
|
38
|
+
#
|
39
|
+
# @example Date.today.to_unit => Unit
|
40
|
+
# @return [RubyUnits::Unit]
|
41
|
+
# @param other [RubyUnits::Unit, String] convert to same units as passed
|
42
|
+
def to_unit(other = nil)
|
43
|
+
other ? RubyUnits::Unit.new(self).convert_to(other) : RubyUnits::Unit.new(self)
|
45
44
|
end
|
46
|
-
end
|
47
|
-
# :nocov_19:
|
48
45
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
return units_datetime_inspect if dump
|
53
|
-
to_s
|
54
|
-
end
|
55
|
-
|
56
|
-
unless Date.instance_methods.include?(:to_date)
|
57
|
-
# :nocov_19:
|
58
|
-
# @return [Date]
|
59
|
-
def to_date
|
60
|
-
Date.civil(year, month, day)
|
46
|
+
# @deprecated
|
47
|
+
def inspect(dump = false)
|
48
|
+
dump ? super : to_s
|
61
49
|
end
|
62
|
-
# :nocov_19:
|
63
50
|
end
|
64
51
|
end
|
52
|
+
|
53
|
+
# @note Do this instead of Date.prepend(RubyUnits::Date) to avoid YARD warnings
|
54
|
+
# @see https://github.com/lsegal/yard/issues/1353
|
55
|
+
class Date
|
56
|
+
prepend RubyUnits::Date
|
57
|
+
end
|