ruby-units 2.3.2 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fb1ccadd6b955b26c4853ecba154e78c4313ef1baa953d9bac365aeccf152912
4
- data.tar.gz: 6c88b7f180d6b30f216dca3a6e990d2a5a4406dd515cc3e756d9f3cb5a5df2c6
3
+ metadata.gz: 9e423976ff1953c233f4085f282b9431d9dc8f7fa840403221eb42d363384809
4
+ data.tar.gz: 22c656c48317d6af891eb3e3e1fbfcecc48fd113a9fff76004c829417b4ed305
5
5
  SHA512:
6
- metadata.gz: 060c9895cc09a6a0de5f6e3a4c28e9c780f8a7b81ac1f73e8e5601f895edb00a6289cfacac4822d6d4bdb6f933985192e8791edb1a33f858b33d0ad75d1f55e4
7
- data.tar.gz: 51b19481a8fbb8fce5a4f37c20ecffb2f5869853f261908a95339ff1b8c8504f2183ab48d26a0981f0e87e63f7c5eac104234eaa5086eb92fb84ca49e38bfa08
6
+ metadata.gz: '096f48bed8904c0e450151e1df844493826b665ffaad305b08c3315c215e97b82643ee450b8e6208930aa936128b835d62a661bc9823302442311da16a02bca9'
7
+ data.tar.gz: 51814f9dc8b31fea8a4bb789a8f7e474a453737d4e9f6eba7ed2548285d99d21608ec14111ec024017abc04e57ea50556be1b597f6cb3688d4d7cd0ba665dfcc
@@ -0,0 +1,16 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: bundler
4
+ directory: "/"
5
+ schedule:
6
+ interval: daily
7
+ time: "10:00"
8
+ open-pull-requests-limit: 10
9
+ ignore:
10
+ - dependency-name: solargraph
11
+ versions:
12
+ - 0.40.2
13
+ - 0.40.3
14
+ - dependency-name: nokogiri
15
+ versions:
16
+ - 1.11.1
@@ -0,0 +1,70 @@
1
+ # For most projects, this workflow file will not need changing; you simply need
2
+ # to commit it to your repository.
3
+ #
4
+ # You may wish to alter this file to override the set of languages analyzed,
5
+ # or to provide custom queries or build logic.
6
+ #
7
+ # ******** NOTE ********
8
+ # We have attempted to detect the languages in your repository. Please check
9
+ # the `language` matrix defined below to confirm you have the correct set of
10
+ # supported CodeQL languages.
11
+ #
12
+ name: "CodeQL"
13
+
14
+ on:
15
+ push:
16
+ branches: [ master ]
17
+ pull_request:
18
+ # The branches below must be a subset of the branches above
19
+ branches: [ master ]
20
+ schedule:
21
+ - cron: '15 17 * * 6'
22
+
23
+ jobs:
24
+ analyze:
25
+ name: Analyze
26
+ runs-on: ubuntu-latest
27
+ permissions:
28
+ actions: read
29
+ contents: read
30
+ security-events: write
31
+
32
+ strategy:
33
+ fail-fast: false
34
+ matrix:
35
+ language: [ 'ruby' ]
36
+ # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
37
+ # Learn more about CodeQL language support at https://git.io/codeql-language-support
38
+
39
+ steps:
40
+ - name: Checkout repository
41
+ uses: actions/checkout@v2
42
+
43
+ # Initializes the CodeQL tools for scanning.
44
+ - name: Initialize CodeQL
45
+ uses: github/codeql-action/init@v2
46
+ with:
47
+ languages: ${{ matrix.language }}
48
+ # If you wish to specify custom queries, you can do so here or in a config file.
49
+ # By default, queries listed here will override any specified in a config file.
50
+ # Prefix the list here with "+" to use these queries and those in the config file.
51
+ # queries: ./path/to/local/query, your-org/your-repo/queries@main
52
+
53
+ # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
54
+ # If this step fails, then you should remove it and run the build manually (see below)
55
+ - name: Autobuild
56
+ uses: github/codeql-action/autobuild@v2
57
+
58
+ # ℹ️ Command-line programs to run using the OS shell.
59
+ # 📚 https://git.io/JvXDl
60
+
61
+ # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
62
+ # and modify them (or add more) to build your code if your project
63
+ # uses a compiled language
64
+
65
+ #- run: |
66
+ # make bootstrap
67
+ # make release
68
+
69
+ - name: Perform CodeQL Analysis
70
+ uses: github/codeql-action/analyze@v2
@@ -15,7 +15,7 @@ jobs:
15
15
  strategy:
16
16
  fail-fast: false
17
17
  matrix:
18
- ruby: ['2.5', '2.6', '2.7', '3.0', 'jruby-9.2']
18
+ ruby: ['2.6', '2.7', '3.0', '3.1', 'jruby-9.3']
19
19
  steps:
20
20
  - uses: actions/checkout@v2
21
21
  - uses: ruby/setup-ruby@v1
@@ -38,3 +38,12 @@ jobs:
38
38
  CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
39
39
  with:
40
40
  coverageCommand: bundle exec rake
41
+ yard:
42
+ runs-on: ubuntu-latest
43
+ steps:
44
+ - uses: actions/checkout@v2
45
+ - uses: ruby/setup-ruby@v1
46
+ with:
47
+ bundler-cache: true
48
+ - name: Build YARD docs
49
+ run: bundle exec yard doc --fail-on-warning
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.5.8
1
+ 2.6.10
data/.solargraph.yml CHANGED
@@ -9,8 +9,8 @@ exclude:
9
9
  require: []
10
10
  domains: []
11
11
  reporters:
12
- - rubocop
13
12
  - require_not_found
13
+ - typecheck
14
14
  require_paths: []
15
15
  plugins: []
16
16
  max_files: 5000
data/.tool-versions ADDED
@@ -0,0 +1,3 @@
1
+ # ruby jruby-9.3.8.0
2
+ # uncomment this to use jruby
3
+ java adoptopenjdk-18.0.1+10
data/CHANGELOG.txt CHANGED
@@ -1,5 +1,9 @@
1
1
  Change Log for Ruby-units
2
2
  =========================
3
+
4
+ see GitHub releases (https://github.com/olbrich/ruby-units/releases) for more recent releases. This file will no longer
5
+ be updated.
6
+
3
7
  2020-12-29 2.3.2 * Remove Jeweler (see #178) also adds Code of Conduct
4
8
  * Fix specs related to Complex comparisons (see #213)
5
9
  * Add support for Ruby 3.0 (also drop support for 2.3 and 2.4) (see #211)
data/Gemfile CHANGED
@@ -1,7 +1,8 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  group :development do
4
- gem 'pry-byebug', platform: :mri
4
+ gem 'debug', '>= 1.0.0', platform: :mri
5
+ gem 'redcarpet', platform: :mri # redcarpet doesn't support jruby
5
6
  gem 'ruby-maven', platform: :jruby
6
7
  gem 'ruby-prof', platform: :mri
7
8
  end
data/Gemfile.lock CHANGED
@@ -1,29 +1,31 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby-units (2.3.2)
4
+ ruby-units (3.0.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- ast (2.4.1)
10
- backport (1.1.2)
11
- benchmark (0.1.1)
12
- byebug (11.1.3)
9
+ ast (2.4.2)
10
+ backport (1.2.0)
11
+ benchmark (0.2.0)
13
12
  coderay (1.1.3)
14
- diff-lcs (1.4.4)
15
- docile (1.3.4)
13
+ debug (1.6.2)
14
+ irb (>= 1.3.6)
15
+ reline (>= 0.3.1)
16
+ diff-lcs (1.5.0)
17
+ docile (1.4.0)
16
18
  e2mmap (0.1.0)
17
- ffi (1.14.2)
18
- ffi (1.14.2-java)
19
- formatador (0.2.5)
20
- guard (2.16.2)
19
+ ffi (1.15.5)
20
+ ffi (1.15.5-java)
21
+ formatador (1.1.0)
22
+ guard (2.18.0)
21
23
  formatador (>= 0.2.4)
22
24
  listen (>= 2.7, < 4.0)
23
25
  lumberjack (>= 1.0.12, < 2.0)
24
26
  nenv (~> 0.1)
25
27
  notiffany (~> 0.0)
26
- pry (>= 0.9.12)
28
+ pry (>= 0.13.0)
27
29
  shellany (~> 0.0)
28
30
  thor (>= 0.18.1)
29
31
  guard-compat (1.2.1)
@@ -31,97 +33,109 @@ GEM
31
33
  guard (~> 2.1)
32
34
  guard-compat (~> 1.1)
33
35
  rspec (>= 2.99.0, < 4.0)
36
+ io-console (0.5.11)
37
+ irb (1.4.1)
38
+ reline (>= 0.3.0)
34
39
  jaro_winkler (1.5.4)
35
40
  jaro_winkler (1.5.4-java)
36
- kramdown (2.3.0)
41
+ json (2.6.2)
42
+ json (2.6.2-java)
43
+ kramdown (2.4.0)
37
44
  rexml
38
45
  kramdown-parser-gfm (1.1.0)
39
46
  kramdown (~> 2.0)
40
- listen (3.3.3)
47
+ listen (3.7.1)
41
48
  rb-fsevent (~> 0.10, >= 0.10.3)
42
49
  rb-inotify (~> 0.9, >= 0.9.10)
43
50
  lumberjack (1.2.8)
44
51
  method_source (1.0.0)
45
- mini_portile2 (2.4.0)
52
+ mini_portile2 (2.8.0)
46
53
  nenv (0.3.0)
47
- nokogiri (1.10.10)
48
- mini_portile2 (~> 2.4.0)
49
- nokogiri (1.10.10-java)
54
+ nokogiri (1.13.8)
55
+ mini_portile2 (~> 2.8.0)
56
+ racc (~> 1.4)
57
+ nokogiri (1.13.8-java)
58
+ racc (~> 1.4)
59
+ nokogiri (1.13.8-x86_64-darwin)
60
+ racc (~> 1.4)
50
61
  notiffany (0.1.3)
51
62
  nenv (~> 0.1)
52
63
  shellany (~> 0.0)
53
- parallel (1.20.1)
54
- parser (2.7.2.0)
64
+ parallel (1.22.1)
65
+ parser (3.1.2.1)
55
66
  ast (~> 2.4.1)
56
- pry (0.13.1)
67
+ pry (0.14.1)
57
68
  coderay (~> 1.1)
58
69
  method_source (~> 1.0)
59
- pry (0.13.1-java)
70
+ pry (0.14.1-java)
60
71
  coderay (~> 1.1)
61
72
  method_source (~> 1.0)
62
73
  spoon (~> 0.0)
63
- pry-byebug (3.9.0)
64
- byebug (~> 11.0)
65
- pry (~> 0.13.0)
66
- rainbow (3.0.0)
67
- rake (13.0.3)
68
- rb-fsevent (0.10.4)
74
+ racc (1.6.0)
75
+ racc (1.6.0-java)
76
+ rainbow (3.1.1)
77
+ rake (13.0.6)
78
+ rb-fsevent (0.11.2)
69
79
  rb-inotify (0.10.1)
70
80
  ffi (~> 1.0)
71
- regexp_parser (2.0.3)
72
- reverse_markdown (2.0.0)
81
+ redcarpet (3.5.1)
82
+ regexp_parser (2.6.0)
83
+ reline (0.3.1)
84
+ io-console (~> 0.5)
85
+ reverse_markdown (2.1.1)
73
86
  nokogiri
74
- rexml (3.2.4)
75
- rspec (3.10.0)
76
- rspec-core (~> 3.10.0)
77
- rspec-expectations (~> 3.10.0)
78
- rspec-mocks (~> 3.10.0)
79
- rspec-core (3.10.1)
80
- rspec-support (~> 3.10.0)
81
- rspec-expectations (3.10.1)
87
+ rexml (3.2.5)
88
+ rspec (3.11.0)
89
+ rspec-core (~> 3.11.0)
90
+ rspec-expectations (~> 3.11.0)
91
+ rspec-mocks (~> 3.11.0)
92
+ rspec-core (3.11.0)
93
+ rspec-support (~> 3.11.0)
94
+ rspec-expectations (3.11.1)
82
95
  diff-lcs (>= 1.2.0, < 2.0)
83
- rspec-support (~> 3.10.0)
84
- rspec-mocks (3.10.1)
96
+ rspec-support (~> 3.11.0)
97
+ rspec-mocks (3.11.1)
85
98
  diff-lcs (>= 1.2.0, < 2.0)
86
- rspec-support (~> 3.10.0)
87
- rspec-support (3.10.1)
88
- rubocop (1.7.0)
99
+ rspec-support (~> 3.11.0)
100
+ rspec-support (3.11.1)
101
+ rubocop (1.36.0)
102
+ json (~> 2.3)
89
103
  parallel (~> 1.10)
90
- parser (>= 2.7.1.5)
104
+ parser (>= 3.1.2.1)
91
105
  rainbow (>= 2.2.2, < 4.0)
92
106
  regexp_parser (>= 1.8, < 3.0)
93
- rexml
94
- rubocop-ast (>= 1.2.0, < 2.0)
107
+ rexml (>= 3.2.5, < 4.0)
108
+ rubocop-ast (>= 1.20.1, < 2.0)
95
109
  ruby-progressbar (~> 1.7)
96
- unicode-display_width (>= 1.4.0, < 2.0)
97
- rubocop-ast (1.3.0)
98
- parser (>= 2.7.1.5)
99
- rubocop-rake (0.5.1)
100
- rubocop
101
- rubocop-rspec (2.1.0)
110
+ unicode-display_width (>= 1.4.0, < 3.0)
111
+ rubocop-ast (1.21.0)
112
+ parser (>= 3.1.1.0)
113
+ rubocop-rake (0.6.0)
102
114
  rubocop (~> 1.0)
103
- rubocop-ast (>= 1.1.0)
104
- ruby-maven (3.3.12)
115
+ rubocop-rspec (2.13.2)
116
+ rubocop (~> 1.33)
117
+ ruby-maven (3.3.13)
105
118
  ruby-maven-libs (~> 3.3.9)
106
119
  ruby-maven-libs (3.3.9)
107
- ruby-prof (1.4.2)
108
- ruby-progressbar (1.10.1)
120
+ ruby-prof (1.4.3)
121
+ ruby-progressbar (1.11.0)
109
122
  shellany (0.0.1)
110
- simplecov (0.20.0)
123
+ simplecov (0.21.2)
111
124
  docile (~> 1.1)
112
125
  simplecov-html (~> 0.11)
113
126
  simplecov_json_formatter (~> 0.1)
114
127
  simplecov-html (0.12.3)
115
- simplecov_json_formatter (0.1.2)
116
- solargraph (0.40.1)
117
- backport (~> 1.1)
128
+ simplecov_json_formatter (0.1.4)
129
+ solargraph (0.47.2)
130
+ backport (~> 1.2)
118
131
  benchmark
119
132
  bundler (>= 1.17.2)
133
+ diff-lcs (~> 1.4)
120
134
  e2mmap
121
135
  jaro_winkler (~> 1.5)
122
136
  kramdown (~> 2.3)
123
137
  kramdown-parser-gfm (~> 1.1)
124
- parser (~> 2.3)
138
+ parser (~> 3.0)
125
139
  reverse_markdown (>= 1.0.5, < 3)
126
140
  rubocop (>= 0.52)
127
141
  thor (~> 1.0)
@@ -131,22 +145,26 @@ GEM
131
145
  ffi
132
146
  terminal-notifier (2.0.0)
133
147
  terminal-notifier-guard (1.7.0)
134
- thor (1.0.1)
135
- tilt (2.0.10)
136
- unicode-display_width (1.7.0)
137
- yard (0.9.26)
148
+ thor (1.2.1)
149
+ tilt (2.0.11)
150
+ unicode-display_width (2.3.0)
151
+ webrick (1.7.0)
152
+ yard (0.9.28)
153
+ webrick (~> 1.7.0)
138
154
 
139
155
  PLATFORMS
140
156
  java
141
157
  ruby
142
158
  universal-java-11
159
+ universal-java-18
143
160
  x86_64-darwin-19
144
161
 
145
162
  DEPENDENCIES
163
+ debug (>= 1.0.0)
146
164
  guard-rspec
147
165
  pry
148
- pry-byebug
149
166
  rake
167
+ redcarpet
150
168
  rspec (~> 3.0)
151
169
  rubocop
152
170
  rubocop-rake
@@ -159,6 +177,8 @@ DEPENDENCIES
159
177
  solargraph
160
178
  terminal-notifier
161
179
  terminal-notifier-guard
180
+ webrick
181
+ yard
162
182
 
163
183
  BUNDLED WITH
164
- 2.2.3
184
+ 2.3.13
data/lib/ruby-units.rb CHANGED
@@ -1,3 +1,2 @@
1
- $LOAD_PATH << File.dirname(__FILE__)
2
1
  require_relative 'ruby_units/namespaced'
3
2
  Unit = RubyUnits::Unit
@@ -1,9 +1,19 @@
1
- class Array
2
- # Construct a unit from an array
3
- # @example [1, 'mm'].to_unit => RubyUnits::Unit.new("1 mm")
4
- # @return (see RubyUnits::Unit#initialize)
5
- # @param [Object] other convert to same units as passed
6
- def to_unit(other = nil)
7
- other ? RubyUnits::Unit.new(self).convert_to(other) : RubyUnits::Unit.new(self)
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
@@ -1,21 +1,34 @@
1
1
  module RubyUnits
2
- class Unit < Numeric
3
- @@cached_units = {}
2
+ # Performance optimizations to avoid creating units unnecessarily
3
+ class Cache
4
+ attr_accessor :data
4
5
 
5
- class Cache
6
- def self.get(key = nil)
7
- key.nil? ? @@cached_units : @@cached_units[key]
8
- end
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
- def self.set(key, value)
11
- @@cached_units[key] = value
12
- end
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
- def self.clear
15
- @@cached_units = {}
16
- @@base_unit_cache = {}
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,15 +11,22 @@ 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
24
24
 
25
25
  # holds actual configuration values for RubyUnits
26
26
  class Configuration
27
- # used to separate the scalar from the unit when generating output.
28
- # set to nil to prevent adding a space to the string representation of a unit
29
- # separators other than ' ' and '' may work, but you may encounter problems
27
+ # Used to separate the scalar from the unit when generating output. A value
28
+ # of `true` will insert a single space, and `false` will prevent adding a
29
+ # space to the string representation of a unit.
30
30
  attr_reader :separator
31
31
 
32
32
  def initialize
@@ -34,7 +34,8 @@ module RubyUnits
34
34
  end
35
35
 
36
36
  def separator=(value)
37
- raise ArgumentError, "configuration 'separator' may only be true or false" unless value.class == TrueClass || value.class == FalseClass
37
+ raise ArgumentError, "configuration 'separator' may only be true or false" unless [true, false].include?(value)
38
+
38
39
  @separator = value ? ' ' : nil
39
40
  end
40
41
  end
@@ -1,64 +1,57 @@
1
1
  require 'date'
2
2
 
3
- # Allow date objects to do offsets by a time unit
4
- # Date.today + Unit.new("1 week") => gives today+1 week
5
- class Date
6
- alias unit_date_add +
7
- # @param [Object] other
8
- # @return [Unit]
9
- def +(other)
10
- case other
11
- when RubyUnits::Unit
12
- other = other.convert_to('d').round if %w[y decade century].include? other.units
13
- unit_date_add(other.convert_to('day').scalar)
14
- else
15
- unit_date_add(other)
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
- alias unit_date_sub -
20
- # @param [Object] other
21
- # @return [Unit]
22
- def -(other)
23
- case other
24
- when RubyUnits::Unit
25
- other = other.convert_to('d').round if %w[y decade century].include? other.units
26
- unit_date_sub(other.convert_to('day').scalar)
27
- else
28
- unit_date_sub(other)
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
- # Construct a unit from a Date
33
- # @example Date.today.to_unit => Unit
34
- # @return (see Unit#initialize)
35
- # @param [Object] other convert to same units as passed
36
- def to_unit(other = nil)
37
- other ? RubyUnits::Unit.new(self).convert_to(other) : RubyUnits::Unit.new(self)
38
- end
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
- alias units_datetime_inspect inspect
50
- # @deprecated
51
- def inspect(dump = false)
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