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 +4 -4
- data/CHANGELOG.md +11 -0
- data/README.md +26 -0
- data/duration_in_words.gemspec +2 -0
- data/lib/duration_in_words/core_ext.rb +11 -0
- data/lib/duration_in_words/methods.rb +1 -0
- data/lib/duration_in_words/version.rb +1 -1
- data/lib/duration_in_words.rb +1 -0
- data/sig/duration_in_words.rbs +6 -0
- metadata +16 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d7b8a55387a6b973edd5e7953a5f563e469be39e03ae3e5fe84a83fbe00b4aa2
|
|
4
|
+
data.tar.gz: b382175e5c913c05521f7b2b00cee53c7375078c70ef132504fcdfc37b7fc1ea
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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'
|
data/duration_in_words.gemspec
CHANGED
|
@@ -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
|
|
@@ -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)
|
data/lib/duration_in_words.rb
CHANGED
data/sig/duration_in_words.rbs
CHANGED
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
|
+
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
|