duration_in_words 0.4.0 → 0.5.0

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: 53a9a76ccc79bc85bd8f85480e62c12783260c31c8a9dd658d2534f1485eb663
4
- data.tar.gz: ed294f375f5d68a38c5665ee3766b171c4a26cde8c209ea9ea05be04333bd5bf
3
+ metadata.gz: d7b8a55387a6b973edd5e7953a5f563e469be39e03ae3e5fe84a83fbe00b4aa2
4
+ data.tar.gz: b382175e5c913c05521f7b2b00cee53c7375078c70ef132504fcdfc37b7fc1ea
5
5
  SHA512:
6
- metadata.gz: 900214bb1801e30866b551fe395bd8695a3d101c4abf919cbf3e1f9e237ccca5af3756cb037fbe5e954377c0b00694a1a5b9f9a52410f8874d76fbca130b962c
7
- data.tar.gz: b82c111999a4ae3078f57bb028926b34bdd37075b02c9f7002d37b9736eb8bd9857932a1d52a73be06c5a931b5038935476678cd827739dffef3aa79e4435af1
6
+ metadata.gz: e0e48f6eb399ea124fc8fd5e1bbad64edea8add1d64823000e36ed9f170fc582b254d1cf5c563a7cc4958e1878c655c98f9f162b7187c4e9f6bf3ffa30fc61c9
7
+ data.tar.gz: 5cf55fb1b2c99e96d29b804cd659c533f9ad184bdf0aa1172ca0c214ad5e647420f35d897fd3b4e81a61cd1f7b4a2336200964933685ac3821361164eb10ca6c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.5.0] - 2026-10-30
4
+
5
+ ### Added
6
+
7
+ - `duration_in_words` accepts an ISO 8601 duration string (e.g. `"PT1H30M"`),
8
+ parsed via `ActiveSupport::Duration.parse`.
9
+ - Opt-in core extension: `require "duration_in_words/core_ext"` adds
10
+ `ActiveSupport::Duration#in_words`.
11
+
1
12
  ## [0.4.0] - 2026-07-14
2
13
 
3
14
  ### Fixed
data/README.md CHANGED
@@ -58,6 +58,24 @@ include ActionView::Helpers::DurationHelper
58
58
  => "2.5m"
59
59
  ```
60
60
 
61
+ An ISO 8601 duration string is parsed with `ActiveSupport::Duration.parse`:
62
+
63
+ ```ruby
64
+ >> duration_in_words("P1DT2H30M")
65
+ => "1d 2h and 30m"
66
+ ```
67
+
68
+ ### Core extension
69
+
70
+ Opt in to calling it directly on a duration:
71
+
72
+ ```ruby
73
+ require "duration_in_words/core_ext"
74
+
75
+ >> (1.day + 2.hours).in_words(format: :full)
76
+ => "1 day and 2 hours"
77
+ ```
78
+
61
79
  ### Using <tt>:format</tt> option:
62
80
 
63
81
  There are two formats available, `:compact`, and `:full`. `:compact` being the default.
@@ -68,6 +86,8 @@ There are two formats available, `:compact`, and `:full`. `:compact` being the d
68
86
  => "1 day, 2 hours, and 30 minutes"
69
87
  ```
70
88
 
89
+ Passing anything other than `:compact` or `:full` (as a symbol or string) raises `ArgumentError`.
90
+
71
91
  ### Using <tt>:locale</tt> option:
72
92
 
73
93
  If you do not pass `:locale`, the helper uses the current `I18n.locale`.
@@ -86,6 +106,9 @@ de:
86
106
  months:
87
107
  one: '%{count}M'
88
108
  other: '%{count}M'
109
+ weeks:
110
+ one: '%{count}W'
111
+ other: '%{count}W'
89
112
  days:
90
113
  one: '%{count}T'
91
114
  other: '%{count}T'
@@ -109,6 +132,9 @@ de:
109
132
  months:
110
133
  one: '%{count} Monat'
111
134
  other: '%{count} Monate'
135
+ weeks:
136
+ one: '%{count} Woche'
137
+ other: '%{count} Wochen'
112
138
  days:
113
139
  one: '%{count} Tag'
114
140
  other: '%{count} Tage'
@@ -41,4 +41,6 @@ Gem::Specification.new do |spec|
41
41
  spec.add_development_dependency "rubocop", "~> 1.21"
42
42
  spec.add_development_dependency "rubocop-rake"
43
43
  spec.add_development_dependency "rubocop-rspec", "~> 2.18.1"
44
+ # ponytail: rubocop-capybara 2.23 breaks rubocop-rspec 2.18; drop when moving to rubocop-rspec 3.x
45
+ spec.add_development_dependency "rubocop-capybara", "< 2.23"
44
46
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "duration_in_words"
4
+
5
+ module ActiveSupport
6
+ class Duration
7
+ def in_words(options = {})
8
+ DurationInWords::Methods.duration_in_words(self, options)
9
+ end
10
+ end
11
+ end
@@ -7,6 +7,7 @@ module DurationInWords
7
7
  VALID_FORMATS = %i[compact full].freeze
8
8
 
9
9
  def duration_in_words(duration, options = {})
10
+ duration = ActiveSupport::Duration.parse(duration) if duration.is_a?(String)
10
11
  raise_type_error(duration) unless duration.is_a?(ActiveSupport::Duration)
11
12
 
12
13
  locale, scope = parse_options(options)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DurationInWords
4
- VERSION = "0.4.0"
4
+ VERSION = "0.5.0"
5
5
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "logger" # activesupport < 7.1 needs it loaded first; concurrent-ruby >= 1.3.5 stopped requiring it
3
4
  require "i18n"
4
5
  require "active_support"
5
6
  require "active_support/core_ext"
@@ -25,6 +25,12 @@ module DurationInWords
25
25
  end
26
26
  end
27
27
 
28
+ module ActiveSupport
29
+ class Duration
30
+ def in_words: (?Hash[Symbol, untyped] options) -> String
31
+ end
32
+ end
33
+
28
34
  module ActionView
29
35
  module Helpers
30
36
  module DurationHelper
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duration_in_words
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Syed Aslam
@@ -135,6 +135,20 @@ dependencies:
135
135
  - - "~>"
136
136
  - !ruby/object:Gem::Version
137
137
  version: 2.18.1
138
+ - !ruby/object:Gem::Dependency
139
+ name: rubocop-capybara
140
+ requirement: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "<"
143
+ - !ruby/object:Gem::Version
144
+ version: '2.23'
145
+ type: :development
146
+ prerelease: false
147
+ version_requirements: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - "<"
150
+ - !ruby/object:Gem::Version
151
+ version: '2.23'
138
152
  description: |-
139
153
  Convert ActiveSupport::Duration objects to concise human readable formats like '2h 30m 45s'
140
154
  with locale support.
@@ -154,6 +168,7 @@ files:
154
168
  - duration_in_words.gemspec
155
169
  - lib/duration_in_words.rb
156
170
  - lib/duration_in_words/action_view/helpers/duration_helper.rb
171
+ - lib/duration_in_words/core_ext.rb
157
172
  - lib/duration_in_words/locales/de.yml
158
173
  - lib/duration_in_words/locales/en.yml
159
174
  - lib/duration_in_words/methods.rb