duration.rb 0.5.2 → 0.6.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 55bc0f38eb9c213a08b6ca49ea69908c2aeff8679637df50ab7309bc564ad457
4
- data.tar.gz: 14032f8850e3499398761abcf3155c1390d22b89e71e1c2be302cfe6b9863f5b
3
+ metadata.gz: 4b96f8854514150e9a991174eee5ab4dbb5f0e829e3e3c15a093b1846a127f06
4
+ data.tar.gz: 7333289ca6c7552ac8db51fcfe6ea03a1101adc5f512a5167e2959ff03e544b8
5
5
  SHA512:
6
- metadata.gz: 41cc6f366ad11f553d299616312fbf325bb7979dfd7f978302a3b0afc4697b2d92dd506b35481deb17718add06377b0037df7d022a1f817010da69396a939cf4
7
- data.tar.gz: ef8d3edc58e19d3a2715901904af9be11600e52e1ec6b03cc5a58e920d69c6db1e4e26632169aa887c6d3ddbf99b9d6da928053f505faa4cf5c8890ad4a4229f
6
+ metadata.gz: 5c763588f6127dd447cdfb7f0ec84230aec91ca79d7b561e76ed8084899e6bdcff073726498bfd079c430cc7e43990fe34b0cd1afa9fb5236ee9c9efa9c66ba7
7
+ data.tar.gz: cd053efb36ff1ac0f323464464ed879d19c6326af14b99aba93af9f3b12908744a00e6838b355e6a45e879236d4d40773072af965b726261ddcb3ebbe3589b54
data/CHANGELOG CHANGED
@@ -1,5 +1,27 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 20260816
4
+
5
+ 0.6.1: Documentation fixes for Months, which said one thing in the README and another in the class comment, and showed a third in the examples.
6
+
7
+ 1. ~ lib/Duration/Months.rb: /Months is slated for removal in 0.5.0/Months is therefore slated for removal/. 0.5.1 dropped the version from README.md, 0.5.0 having been and gone with Months still in place, but left the class comment still naming it, so the two have disagreed since and the comment is now two minor versions stale.
8
+ 2. ~ README.md: + 6.months.ago and 6.months.hence to the Time Calculations examples, each with the mean month noted beside it. Every other unit was shown and Months alone omitted, which implies that Months does not answer ago and hence, when 0.4.0 decided that it does and A Note on Months says as much eleven lines below. The examples are what is read first, so the omission was the louder statement of the two.
9
+ 3. ~ Duration::VERSION: /0.6.0/0.6.1/
10
+
11
+
12
+ ## 20260812
13
+
14
+ 0.6.0: The unit classes are now autoloaded so as to avoid circular loading messages when running the tests. It's faster too!
15
+
16
+ 1. + lib/duration.rb: Autoload each unit file, and Common and Relative.
17
+ 2. ~ lib/Duration/*.rb: - require_relative './Common', './Relative'
18
+ 3. ~ lib/Duration/*.rb: + require_relative '../duration'. Each unit had required both of its neighbours, so that every adjacent pair was a cycle and Ruby warned upon each under -w. The ring was connected besides, so requiring any one unit dragged in eleven files of the thirteen and no part of the gem could be left unread. Requiring one now brings five, and the rest arrive as they are named.
19
+ 4. ~ lib/duration.rb: Add a note why VERSION is required and not declared, being the one exception.
20
+ 5. ~ README.md: Add a line in the Loading section.
21
+ 6. + test/loading_test.rb: that a single unit file required alone still converts, that a unit never named is never read, that one named is, and that the whole loads without warning under -w. Each runs in a process of its own, the test helper having already loaded everything in this one.
22
+ 7. ~ Duration::VERSION: /0.5.2/0.6.0/
23
+
24
+
3
25
  ## 20260812
4
26
 
5
27
  0.5.2: + gemspec test.
data/README.md CHANGED
@@ -52,8 +52,12 @@ require 'duration-numeric' # opt in to the Numeric sugar (5.minutes, etc.),
52
52
  ```
53
53
 
54
54
  The examples below use the `Numeric` sugar, so they assume
55
- `require 'duration-numeric'`. Without it, construct durations directly with
56
- `Duration::Minutes.new(5)` and friends.
55
+ `require 'duration-numeric'`. Without it durations are constructed directly with
56
+ `Duration::Minutes.new(5)` and so on.
57
+
58
+ Either require declares where the unit classes are without reading them. A unit
59
+ file is read when its class is first named, so a program dealing in seconds and
60
+ minutes reads the files for seconds and minutes and leaves the rest unread.
57
61
 
58
62
  ## Usage
59
63
 
@@ -123,12 +127,19 @@ The examples below use the `Numeric` sugar, so they assume
123
127
  5.days.ago # => #<Time:> (now - 5.days.to_seconds.to_f)
124
128
  6.weeks.ago # => #<Time:> (now - 6.weeks.to_seconds.to_f)
125
129
 
130
+ # Months too, but by the Gregorian mean month rather than a calendar month, so
131
+ # the result is approximate. See A Note on Months below.
132
+ 6.months.ago # => #<Time:> (now - 6.months.to_seconds.to_f)
133
+
126
134
  # The future
127
135
  2.seconds.hence # => #<Time:> (now + 2.seconds.to_seconds.to_f)
128
136
  3.minutes.hence # => #<Time:> (now + 3.minutes.to_seconds.to_f)
129
137
  4.hours.hence # => #<Time:> (now + 4.hours.to_seconds.to_f)
130
138
  5.days.hence # => #<Time:> (now + 5.days.to_seconds.to_f)
131
139
  6.weeks.hence # => #<Time:> (now + 6.weeks.to_seconds.to_f)
140
+
141
+ # Again by the mean month, and so approximate:
142
+ 6.months.hence # => #<Time:> (now + 6.months.to_seconds.to_f)
132
143
  ```
133
144
 
134
145
  ### A Note on Months
data/lib/Duration/Days.rb CHANGED
@@ -1,10 +1,7 @@
1
1
  # Duration/Days.rb
2
2
  # Duration::Days
3
3
 
4
- require_relative './Common'
5
- require_relative './Relative'
6
- require_relative './Hours'
7
- require_relative './Weeks'
4
+ require_relative '../duration'
8
5
 
9
6
  module Duration
10
7
  class Days
@@ -1,10 +1,7 @@
1
1
  # Duration/Hours.rb
2
2
  # Duration::Hours
3
3
 
4
- require_relative './Common'
5
- require_relative './Relative'
6
- require_relative './Minutes'
7
- require_relative './Days'
4
+ require_relative '../duration'
8
5
 
9
6
  module Duration
10
7
  class Hours
@@ -1,10 +1,7 @@
1
1
  # Duration/Microseconds.rb
2
2
  # Duration::Microseconds
3
3
 
4
- require_relative './Common'
5
- require_relative './Relative'
6
- require_relative './Nanoseconds'
7
- require_relative './Milliseconds'
4
+ require_relative '../duration'
8
5
 
9
6
  module Duration
10
7
  class Microseconds
@@ -1,10 +1,7 @@
1
1
  # Duration/Milliseconds.rb
2
2
  # Duration::Milliseconds
3
3
 
4
- require_relative './Common'
5
- require_relative './Relative'
6
- require_relative './Microseconds'
7
- require_relative './Seconds'
4
+ require_relative '../duration'
8
5
 
9
6
  module Duration
10
7
  class Milliseconds
@@ -1,10 +1,7 @@
1
1
  # Duration/Minutes.rb
2
2
  # Duration::Minutes
3
3
 
4
- require_relative './Common'
5
- require_relative './Relative'
6
- require_relative './Seconds'
7
- require_relative './Hours'
4
+ require_relative '../duration'
8
5
 
9
6
  module Duration
10
7
  class Minutes
@@ -1,9 +1,7 @@
1
1
  # Duration/Months.rb
2
2
  # Duration::Months
3
3
 
4
- require_relative './Common'
5
- require_relative './Relative'
6
- require_relative './Weeks'
4
+ require_relative '../duration'
7
5
 
8
6
  module Duration
9
7
  # A month is not a fixed quantity: its length depends on the calendar. The
@@ -13,7 +11,7 @@ module Duration
13
11
  #
14
12
  # ago and hence (via Relative) inherit the same caveat: they displace by the
15
13
  # mean month rather than an actual calendar month, so they are approximate,
16
- # not calendar-correct. Months is slated for removal in 0.5.0.
14
+ # not calendar-correct. Months is therefore slated for removal.
17
15
  class Months
18
16
  include Common
19
17
  include Relative
@@ -1,9 +1,7 @@
1
1
  # Duration/Nanoseconds.rb
2
2
  # Duration::Nanoseconds
3
3
 
4
- require_relative './Common'
5
- require_relative './Relative'
6
- require_relative './Microseconds'
4
+ require_relative '../duration'
7
5
 
8
6
  module Duration
9
7
  class Nanoseconds
@@ -1,10 +1,7 @@
1
1
  # Duration/Seconds.rb
2
2
  # Duration::Seconds
3
3
 
4
- require_relative './Common'
5
- require_relative './Relative'
6
- require_relative './Milliseconds'
7
- require_relative './Minutes'
4
+ require_relative '../duration'
8
5
 
9
6
  module Duration
10
7
  class Seconds
@@ -1,3 +1,3 @@
1
1
  module Duration
2
- VERSION = '0.5.2'
2
+ VERSION = '0.6.1'
3
3
  end
@@ -1,10 +1,7 @@
1
1
  # Duration/Weeks.rb
2
2
  # Duration::Weeks
3
3
 
4
- require_relative './Common'
5
- require_relative './Relative'
6
- require_relative './Days'
7
- require_relative './Months'
4
+ require_relative '../duration'
8
5
 
9
6
  module Duration
10
7
  class Weeks
data/lib/duration.rb CHANGED
@@ -1,15 +1,24 @@
1
1
  # Duration.rb
2
2
  # Duration
3
3
 
4
- module Duration; end
5
-
6
- require_relative 'Duration/Nanoseconds'
7
- require_relative 'Duration/Microseconds'
8
- require_relative 'Duration/Milliseconds'
9
- require_relative 'Duration/Seconds'
10
- require_relative 'Duration/Minutes'
11
- require_relative 'Duration/Hours'
12
- require_relative 'Duration/Days'
13
- require_relative 'Duration/Weeks'
14
- require_relative 'Duration/Months'
4
+ # Previously, neighbouring units which are used conversion methods used to be requires at the top of each file, so that every adjacent pair was a cycle and Ruby warned upon each under -w.
5
+
6
+ # Now, a unit file is read when its class is first named and not before, which is what lets a program dealing in seconds and minutes loads only Seconds and Minutes, so that units are may easily be left unused.
7
+
8
+ module Duration
9
+ autoload :Common, File.expand_path('Duration/Common', __dir__)
10
+ autoload :Relative, File.expand_path('Duration/Relative', __dir__)
11
+ autoload :Nanoseconds, File.expand_path('Duration/Nanoseconds', __dir__)
12
+ autoload :Microseconds, File.expand_path('Duration/Microseconds', __dir__)
13
+ autoload :Milliseconds, File.expand_path('Duration/Milliseconds', __dir__)
14
+ autoload :Seconds, File.expand_path('Duration/Seconds', __dir__)
15
+ autoload :Minutes, File.expand_path('Duration/Minutes', __dir__)
16
+ autoload :Hours, File.expand_path('Duration/Hours', __dir__)
17
+ autoload :Days, File.expand_path('Duration/Days', __dir__)
18
+ autoload :Weeks, File.expand_path('Duration/Weeks', __dir__)
19
+ autoload :Months, File.expand_path('Duration/Months', __dir__)
20
+ end
21
+
22
+ # VERSION is required rather than autoloaded, and is the one exception, as there nothing which will load it at runtime.
23
+
15
24
  require_relative 'Duration/VERSION'
@@ -0,0 +1,32 @@
1
+ # test/loading_test.rb
2
+
3
+ require_relative './test_helper'
4
+
5
+ # Each of these wants a process of its own. Within this one the test helper has already loaded the lot, so nothing here could tell a unit which was declared from a unit which was read.
6
+
7
+ describe 'loading' do
8
+ def ruby(source, *flags)
9
+ lib = File.expand_path('../lib', __dir__)
10
+ IO.popen(['ruby', *flags, "-I#{lib}", '-e', source], err: [:child, :out]){|io| io.read}.strip
11
+ end
12
+
13
+ it "converts when a single unit file is required alone" do
14
+ _(ruby('require "Duration/Seconds"; print Duration::Seconds.new(90).to_minutes.to_f')) \
15
+ .must_equal('1.5')
16
+ end
17
+
18
+ it "does not read a unit which is never named" do
19
+ _(ruby('require "duration.rb"; Duration::Seconds; print $LOADED_FEATURES.grep(/Months/).size')) \
20
+ .must_equal('0')
21
+ end
22
+
23
+ it "reads a unit as soon as it is named" do
24
+ _(ruby('require "duration.rb"; Duration::Months; print $LOADED_FEATURES.grep(/Months/).size')) \
25
+ .must_equal('1')
26
+ end
27
+
28
+ it "loads without warning under -w, no unit requiring another" do
29
+ _(ruby('require "duration.rb"; Duration::Months.new(1).to_nanoseconds; print "ok"', '-w')) \
30
+ .must_equal('ok')
31
+ end
32
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duration.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran
@@ -93,6 +93,7 @@ files:
93
93
  - test/Duration/VERSION_test.rb
94
94
  - test/Duration/Weeks_test.rb
95
95
  - test/gemspec_test.rb
96
+ - test/loading_test.rb
96
97
  - test/test_helper.rb
97
98
  homepage: http://github.com/thoran/duration.rb
98
99
  licenses: