duration_in_words 0.2.0 → 0.4.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/.rubocop.yml +21 -6
- data/CHANGELOG.md +43 -1
- data/README.md +130 -10
- data/Rakefile +4 -0
- data/duration_in_words.gemspec +44 -0
- data/lib/duration_in_words/action_view/helpers/duration_helper.rb +2 -2
- data/lib/duration_in_words/locales/de.yml +6 -0
- data/lib/duration_in_words/locales/en.yml +6 -0
- data/lib/duration_in_words/methods.rb +16 -13
- data/lib/duration_in_words/version.rb +1 -1
- data/lib/duration_in_words.rb +2 -3
- data/sig/duration_in_words.rbs +33 -1
- metadata +51 -10
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 53a9a76ccc79bc85bd8f85480e62c12783260c31c8a9dd658d2534f1485eb663
|
|
4
|
+
data.tar.gz: ed294f375f5d68a38c5665ee3766b171c4a26cde8c209ea9ea05be04333bd5bf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 900214bb1801e30866b551fe395bd8695a3d101c4abf919cbf3e1f9e237ccca5af3756cb037fbe5e954377c0b00694a1a5b9f9a52410f8874d76fbca130b962c
|
|
7
|
+
data.tar.gz: b82c111999a4ae3078f57bb028926b34bdd37075b02c9f7002d37b9736eb8bd9857932a1d52a73be06c5a931b5038935476678cd827739dffef3aa79e4435af1
|
data/.rubocop.yml
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
|
-
require:
|
|
1
|
+
require:
|
|
2
|
+
- rubocop-rspec
|
|
3
|
+
|
|
4
|
+
plugins:
|
|
5
|
+
- rubocop-rake
|
|
2
6
|
|
|
3
7
|
AllCops:
|
|
4
8
|
TargetRubyVersion: 2.6
|
|
9
|
+
NewCops: enable
|
|
10
|
+
|
|
11
|
+
# This gem keeps development dependencies in the gemspec, which matches the
|
|
12
|
+
# standard Bundler gem template used to generate it.
|
|
13
|
+
Gemspec/DevelopmentDependencies:
|
|
14
|
+
Enabled: false
|
|
5
15
|
|
|
6
16
|
# Commonly used screens these days easily fit more than 80 characters.
|
|
7
17
|
Layout/LineLength:
|
|
@@ -25,7 +35,7 @@ Layout/SpaceAroundEqualsInParameterDefault:
|
|
|
25
35
|
# Enforcing double quotes reduces the times where you need to change them
|
|
26
36
|
# when introducing an interpolation. Use single quotes only if their semantics
|
|
27
37
|
# are needed.
|
|
28
|
-
|
|
38
|
+
Style/StringLiterals:
|
|
29
39
|
EnforcedStyle: double_quotes
|
|
30
40
|
|
|
31
41
|
Style/StringLiteralsInInterpolation:
|
|
@@ -36,10 +46,10 @@ Style/StringLiteralsInInterpolation:
|
|
|
36
46
|
Style/SymbolArray:
|
|
37
47
|
Enabled: true
|
|
38
48
|
|
|
39
|
-
#
|
|
49
|
+
# The old style configuration for this cop has been removed in recent RuboCop
|
|
50
|
+
# versions, so keep it disabled instead of carrying invalid options.
|
|
40
51
|
Style/OptionHash:
|
|
41
|
-
|
|
42
|
-
EnforcedColonStyle: table
|
|
52
|
+
Enabled: false
|
|
43
53
|
|
|
44
54
|
# Mixing the styles looks just silly.
|
|
45
55
|
Style/HashSyntax:
|
|
@@ -73,7 +83,7 @@ Style/RaiseArgs:
|
|
|
73
83
|
|
|
74
84
|
# Indenting the chained dots beneath each other is not supported by this cop,
|
|
75
85
|
# see https://github.com/bbatsov/rubocop/issues/1633
|
|
76
|
-
|
|
86
|
+
Layout/MultilineOperationIndentation:
|
|
77
87
|
Enabled: false
|
|
78
88
|
|
|
79
89
|
# Fail is an alias of raise. Avoid aliases, it's more cognitive load for no gain.
|
|
@@ -134,3 +144,8 @@ Style/MethodDefParentheses:
|
|
|
134
144
|
|
|
135
145
|
RSpec/MultipleExpectations:
|
|
136
146
|
Max: 2
|
|
147
|
+
|
|
148
|
+
# This gem does not use Capybara, and the bundled cop currently crashes when
|
|
149
|
+
# inspecting these plain RSpec examples under the pinned plugin set.
|
|
150
|
+
Capybara/RSpec/PredicateMatcher:
|
|
151
|
+
Enabled: false
|
data/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,46 @@
|
|
|
1
|
-
## [
|
|
1
|
+
## [0.4.0] - 2026-07-14
|
|
2
|
+
|
|
3
|
+
### Fixed
|
|
4
|
+
|
|
5
|
+
- Stop calling `I18n.reload!` when setting up locale files. It was discarding
|
|
6
|
+
any translations the host app had already stored in memory (e.g. via
|
|
7
|
+
`I18n.backend.store_translations`), not just ones loaded from files.
|
|
8
|
+
- Removed trailing whitespace from the `de` locale file.
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- `duration_in_words` now raises `ArgumentError` for an unrecognized `:format`
|
|
13
|
+
value instead of silently falling back to `:compact`.
|
|
14
|
+
- CI now runs the test suite against a matrix of supported Ruby versions
|
|
15
|
+
(2.6, 3.1, 3.4) instead of a single pinned version, and runs RuboCop and
|
|
16
|
+
`bundler-audit` as separate jobs.
|
|
17
|
+
- Expanded the RBS signatures beyond `VERSION` to cover
|
|
18
|
+
`DurationInWords::Methods` and the `ActionView` helper.
|
|
19
|
+
|
|
20
|
+
## [0.3.1] - 2026-03-28
|
|
21
|
+
|
|
22
|
+
### Fixed
|
|
23
|
+
|
|
24
|
+
- Respect the current `I18n.locale` by default when formatting durations.
|
|
25
|
+
- Delegate pluralization to I18n so locales with plural forms beyond `one` and `other` are handled correctly.
|
|
26
|
+
|
|
27
|
+
### Changed
|
|
28
|
+
|
|
29
|
+
- Modernized the RuboCop configuration for the current toolchain and added RubyGems MFA metadata.
|
|
30
|
+
|
|
31
|
+
## [0.3.0] - 2025-08-20
|
|
32
|
+
|
|
33
|
+
### Added
|
|
34
|
+
|
|
35
|
+
- Support for `weeks` as a duration unit by adding the necessary translations to the `en` and `de` locale files.
|
|
36
|
+
|
|
37
|
+
## [0.2.0] - 2023-02-04
|
|
38
|
+
|
|
39
|
+
### Added
|
|
40
|
+
|
|
41
|
+
- Support for `:full` format for more descriptive output (e.g., "1 day, 2 hours, and 30 minutes").
|
|
42
|
+
- Internationalization (i18n) support using the `:locale` option.
|
|
43
|
+
- Handling of fractional duration values (e.g., `2.5.minutes`).
|
|
2
44
|
|
|
3
45
|
## [0.1.0] - 2023-02-04
|
|
4
46
|
|
data/README.md
CHANGED
|
@@ -1,22 +1,142 @@
|
|
|
1
|
-
# DurationInWords
|
|
1
|
+
# DurationInWords 
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`duration_in_words` provides a view helper to convert [ActiveSupport::Duration](https://api.rubyonrails.org/classes/ActiveSupport/Duration.html) objects into concise string like `1h 20m and 30s`, with locale support.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Why?
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Currently, there is no direct way to format `ActiveSupport::Duration` objects in `Rails`. You'd have to resort to using the `#inspect`, which provides limited configuration options. Also, the locale support in the `#inspect` was removed around `Rails 5.1`.
|
|
8
|
+
|
|
9
|
+
You could do something like the following to format an `ActiveSupport::Duration` object by hand in a view helper:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
def duration_as_sentence(duration)
|
|
13
|
+
parts = duration.parts
|
|
14
|
+
units = [:days, :hours, :minutes]
|
|
15
|
+
map = {
|
|
16
|
+
:days => { :one => :d },
|
|
17
|
+
:hours => { :one => :h, :other => :hrs },
|
|
18
|
+
:minutes => { :one => :m, :other => :mins }
|
|
19
|
+
}
|
|
8
20
|
|
|
9
|
-
|
|
21
|
+
parts.
|
|
22
|
+
sort_by { |unit, _| units.index(unit) }.
|
|
23
|
+
map { |unit, val| "#{val} #{val == 1 ? map[unit][:one].to_s : map[unit][:other].to_s}" }.
|
|
24
|
+
to_sentence
|
|
25
|
+
end
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
This gem does something similar along with providing a flexible way of defining formats in locale files and giving you an option to switch between `:compact`, and `:full` formats.
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
10
31
|
|
|
11
|
-
|
|
32
|
+
Add to your `Gemfile`:
|
|
12
33
|
|
|
13
|
-
|
|
34
|
+
```ruby
|
|
35
|
+
gem "duration_in_words"
|
|
36
|
+
```
|
|
14
37
|
|
|
15
|
-
|
|
38
|
+
Install the gem by running `bundle install`.
|
|
16
39
|
|
|
17
40
|
## Usage
|
|
18
41
|
|
|
19
|
-
|
|
42
|
+
```ruby
|
|
43
|
+
include ActionView::Helpers::DurationHelper
|
|
44
|
+
|
|
45
|
+
>> duration = 2.hours
|
|
46
|
+
>> duration_in_words(duration)
|
|
47
|
+
=> "2h"
|
|
48
|
+
>> duration = 1.day + 2.hours + 30.minutes
|
|
49
|
+
>> duration_in_words(duration)
|
|
50
|
+
=> "1d 2h and 30m"
|
|
51
|
+
>> duration = 2.5.minutes
|
|
52
|
+
>> duration_in_words(duration)
|
|
53
|
+
=> "2.5m"
|
|
54
|
+
>> duration = 3.weeks
|
|
55
|
+
>> duration_in_words(duration)
|
|
56
|
+
=> "3wks."
|
|
57
|
+
>> duration_in_words(duration)
|
|
58
|
+
=> "2.5m"
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Using <tt>:format</tt> option:
|
|
62
|
+
|
|
63
|
+
There are two formats available, `:compact`, and `:full`. `:compact` being the default.
|
|
64
|
+
|
|
65
|
+
```ruby
|
|
66
|
+
>> duration = 1.day + 2.hours + 30.minutes
|
|
67
|
+
>> duration_in_words(duration, format: :full)
|
|
68
|
+
=> "1 day, 2 hours, and 30 minutes"
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Using <tt>:locale</tt> option:
|
|
72
|
+
|
|
73
|
+
If you do not pass `:locale`, the helper uses the current `I18n.locale`.
|
|
74
|
+
|
|
75
|
+
Given this locale dictionary:
|
|
76
|
+
|
|
77
|
+
```yaml
|
|
78
|
+
de:
|
|
79
|
+
duration:
|
|
80
|
+
in_words:
|
|
81
|
+
format:
|
|
82
|
+
compact:
|
|
83
|
+
years:
|
|
84
|
+
one: '%{count}J'
|
|
85
|
+
other: '%{count}J'
|
|
86
|
+
months:
|
|
87
|
+
one: '%{count}M'
|
|
88
|
+
other: '%{count}M'
|
|
89
|
+
days:
|
|
90
|
+
one: '%{count}T'
|
|
91
|
+
other: '%{count}T'
|
|
92
|
+
hours:
|
|
93
|
+
one: '%{count}Std.'
|
|
94
|
+
other: '%{count}Std.'
|
|
95
|
+
minutes:
|
|
96
|
+
one: '%{count}Min'
|
|
97
|
+
other: '%{count}Min'
|
|
98
|
+
seconds:
|
|
99
|
+
one: '%{count}s'
|
|
100
|
+
other: '%{count}s'
|
|
101
|
+
support:
|
|
102
|
+
words_connector: ' '
|
|
103
|
+
two_words_connector: ' und '
|
|
104
|
+
last_word_connector: ' und '
|
|
105
|
+
full:
|
|
106
|
+
years:
|
|
107
|
+
one: '%{count} Jahr'
|
|
108
|
+
other: '%{count} Jahre'
|
|
109
|
+
months:
|
|
110
|
+
one: '%{count} Monat'
|
|
111
|
+
other: '%{count} Monate'
|
|
112
|
+
days:
|
|
113
|
+
one: '%{count} Tag'
|
|
114
|
+
other: '%{count} Tage'
|
|
115
|
+
hours:
|
|
116
|
+
one: '%{count} Stunde'
|
|
117
|
+
other: '%{count} Stunden'
|
|
118
|
+
minutes:
|
|
119
|
+
one: '%{count} Minute'
|
|
120
|
+
other: '%{count} Minuten'
|
|
121
|
+
seconds:
|
|
122
|
+
one: '%{count} Sekunde'
|
|
123
|
+
other: '%{count} Sekunden'
|
|
124
|
+
support:
|
|
125
|
+
words_connector: ', '
|
|
126
|
+
two_words_connector: ' und '
|
|
127
|
+
last_word_connector: ', und '
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
```ruby
|
|
131
|
+
>> duration = 1.day + 2.hours + 30.minutes
|
|
132
|
+
>> duration_in_words(duration, locale: :de)
|
|
133
|
+
=> "1T 2Std. und 30Min"
|
|
134
|
+
>> duration = 3.weeks
|
|
135
|
+
>> duration_in_words(duration, locale: :de)
|
|
136
|
+
=> "3W"
|
|
137
|
+
>> duration_in_words(duration, format: :full, locale: :de)
|
|
138
|
+
>> "1 Tag 2 Stunden und 30 Minuten"
|
|
139
|
+
```
|
|
20
140
|
|
|
21
141
|
## Development
|
|
22
142
|
|
|
@@ -26,7 +146,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
|
26
146
|
|
|
27
147
|
## Contributing
|
|
28
148
|
|
|
29
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
|
149
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/aslam/duration_in_words.
|
|
30
150
|
|
|
31
151
|
## License
|
|
32
152
|
|
data/Rakefile
CHANGED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "lib/duration_in_words/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "duration_in_words"
|
|
7
|
+
spec.version = DurationInWords::VERSION
|
|
8
|
+
spec.authors = ["Syed Aslam"]
|
|
9
|
+
spec.email = ["aslam.maqsood@gmail.com"]
|
|
10
|
+
|
|
11
|
+
spec.summary = "Report ActiveSupport::Duration in concise human readable formats."
|
|
12
|
+
spec.description = "Convert ActiveSupport::Duration objects to concise human readable formats like '2h 30m 45s'
|
|
13
|
+
with locale support."
|
|
14
|
+
spec.homepage = "https://github.com/aslam/duration_in_words"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
spec.required_ruby_version = ">= 2.6.0"
|
|
17
|
+
|
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
19
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
|
20
|
+
spec.metadata["changelog_uri"] = "https://github.com/aslam/duration_in_words/blob/main/CHANGELOG.md"
|
|
21
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
|
22
|
+
|
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
25
|
+
spec.files = Dir.chdir(__dir__) do
|
|
26
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
|
27
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
spec.bindir = "exe"
|
|
31
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
32
|
+
spec.require_paths = ["lib"]
|
|
33
|
+
|
|
34
|
+
spec.add_dependency "activesupport", ">= 6.0"
|
|
35
|
+
spec.add_dependency "i18n", "~> 1.12"
|
|
36
|
+
|
|
37
|
+
spec.add_development_dependency "bundler-audit"
|
|
38
|
+
spec.add_development_dependency "racc"
|
|
39
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
|
40
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
41
|
+
spec.add_development_dependency "rubocop", "~> 1.21"
|
|
42
|
+
spec.add_development_dependency "rubocop-rake"
|
|
43
|
+
spec.add_development_dependency "rubocop-rspec", "~> 2.18.1"
|
|
44
|
+
end
|
|
@@ -9,8 +9,8 @@ module ActionView
|
|
|
9
9
|
#
|
|
10
10
|
# === Options
|
|
11
11
|
# * <tt>:format</tt> - The format to be used in reporting the duration, :full or :compact (default: :compact)
|
|
12
|
-
# * <tt>:locale</tt> -
|
|
13
|
-
# the 'support.array' namespace in the corresponding dictionary file.
|
|
12
|
+
# * <tt>:locale</tt> - Defaults to the current +I18n.locale+. You can also pass a locale explicitly and use the
|
|
13
|
+
# connector options defined on the 'support.array' namespace in the corresponding dictionary file.
|
|
14
14
|
#
|
|
15
15
|
# === Examples
|
|
16
16
|
# d = 1.day + 2.hours + 30.minutes
|
|
@@ -9,6 +9,9 @@ de:
|
|
|
9
9
|
months:
|
|
10
10
|
one: '%{count}M'
|
|
11
11
|
other: '%{count}M'
|
|
12
|
+
weeks:
|
|
13
|
+
one: '%{count}W'
|
|
14
|
+
other: '%{count}W'
|
|
12
15
|
days:
|
|
13
16
|
one: '%{count}T'
|
|
14
17
|
other: '%{count}T'
|
|
@@ -32,6 +35,9 @@ de:
|
|
|
32
35
|
months:
|
|
33
36
|
one: '%{count} Monat'
|
|
34
37
|
other: '%{count} Monate'
|
|
38
|
+
weeks:
|
|
39
|
+
one: '%{count} Woche'
|
|
40
|
+
other: '%{count} Wochen'
|
|
35
41
|
days:
|
|
36
42
|
one: '%{count} Tag'
|
|
37
43
|
other: '%{count} Tage'
|
|
@@ -9,6 +9,9 @@ en:
|
|
|
9
9
|
months:
|
|
10
10
|
one: '%{count}mo.'
|
|
11
11
|
other: '%{count}mos.'
|
|
12
|
+
weeks:
|
|
13
|
+
one: '%{count}wk.'
|
|
14
|
+
other: '%{count}wks.'
|
|
12
15
|
days:
|
|
13
16
|
one: '%{count}d'
|
|
14
17
|
other: '%{count}d'
|
|
@@ -32,6 +35,9 @@ en:
|
|
|
32
35
|
months:
|
|
33
36
|
one: '%{count} month'
|
|
34
37
|
other: '%{count} months'
|
|
38
|
+
weeks:
|
|
39
|
+
one: '%{count} week'
|
|
40
|
+
other: '%{count} weeks'
|
|
35
41
|
days:
|
|
36
42
|
one: '%{count} day'
|
|
37
43
|
other: '%{count} days'
|
|
@@ -4,16 +4,15 @@ module DurationInWords
|
|
|
4
4
|
module Methods
|
|
5
5
|
extend self
|
|
6
6
|
|
|
7
|
+
VALID_FORMATS = %i[compact full].freeze
|
|
8
|
+
|
|
7
9
|
def duration_in_words(duration, options = {})
|
|
8
10
|
raise_type_error(duration) unless duration.is_a?(ActiveSupport::Duration)
|
|
9
11
|
|
|
10
12
|
locale, scope = parse_options(options)
|
|
11
13
|
parts = duration.parts
|
|
12
14
|
|
|
13
|
-
if parts.empty?
|
|
14
|
-
key = "seconds.#{duration.value == 1 ? 'one' : 'other'}"
|
|
15
|
-
return I18n.t(key, count: duration.value, scope: scope, locale: locale)
|
|
16
|
-
end
|
|
15
|
+
return I18n.t(:seconds, count: duration.value, scope: scope, locale: locale) if parts.empty?
|
|
17
16
|
|
|
18
17
|
sentencify(parts, scope, locale)
|
|
19
18
|
end
|
|
@@ -21,23 +20,27 @@ module DurationInWords
|
|
|
21
20
|
private
|
|
22
21
|
|
|
23
22
|
def parse_options(options)
|
|
24
|
-
format = options.fetch(:format, :compact)
|
|
25
|
-
locale = options.fetch(:locale,
|
|
23
|
+
format = normalize_format(options.fetch(:format, :compact))
|
|
24
|
+
locale = options.fetch(:locale, I18n.locale)
|
|
26
25
|
|
|
27
|
-
scope = format
|
|
26
|
+
scope = format == :full ? I18N_SCOPE_FULL : DEFAULT_I18N_SCOPE
|
|
28
27
|
|
|
29
28
|
[locale, scope]
|
|
30
29
|
end
|
|
31
30
|
|
|
31
|
+
def normalize_format(format)
|
|
32
|
+
symbol = format.respond_to?(:to_sym) ? format.to_sym : format
|
|
33
|
+
|
|
34
|
+
return symbol if VALID_FORMATS.include?(symbol)
|
|
35
|
+
|
|
36
|
+
raise ArgumentError,
|
|
37
|
+
"invalid :format, #{format.inspect} given. Valid formats: #{VALID_FORMATS.map(&:inspect).join(', ')}"
|
|
38
|
+
end
|
|
39
|
+
|
|
32
40
|
def sentencify(parts, scope, locale)
|
|
33
41
|
parts
|
|
34
42
|
.sort_by { |unit, _| ActiveSupport::Duration::PARTS.index(unit) }
|
|
35
|
-
.map { |unit, val|
|
|
36
|
-
case val
|
|
37
|
-
when 1 then I18n.t("#{unit}.one", count: val, scope: scope, locale: locale)
|
|
38
|
-
else I18n.t("#{unit}.other", count: val, scope: scope, locale: locale)
|
|
39
|
-
end
|
|
40
|
-
}
|
|
43
|
+
.map { |unit, val| I18n.t(unit, count: val, scope: scope, locale: locale) }
|
|
41
44
|
.to_sentence(sentence_options(scope, locale))
|
|
42
45
|
end
|
|
43
46
|
|
data/lib/duration_in_words.rb
CHANGED
|
@@ -13,8 +13,8 @@ module DurationInWords
|
|
|
13
13
|
autoload :Methods, "duration_in_words/methods"
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
I18N_SCOPE_FULL = :
|
|
17
|
-
DEFAULT_I18N_SCOPE = :
|
|
16
|
+
I18N_SCOPE_FULL = :"duration.in_words.format.full"
|
|
17
|
+
DEFAULT_I18N_SCOPE = :"duration.in_words.format.compact"
|
|
18
18
|
|
|
19
19
|
module_function
|
|
20
20
|
|
|
@@ -22,7 +22,6 @@ module DurationInWords
|
|
|
22
22
|
locale_files = Dir[File.join File.dirname(__FILE__), "duration_in_words/locales", "*.yml"]
|
|
23
23
|
|
|
24
24
|
I18n.load_path.unshift(*locale_files)
|
|
25
|
-
I18n.reload!
|
|
26
25
|
end
|
|
27
26
|
end
|
|
28
27
|
|
data/sig/duration_in_words.rbs
CHANGED
|
@@ -1,4 +1,36 @@
|
|
|
1
1
|
module DurationInWords
|
|
2
2
|
VERSION: String
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
I18N_SCOPE_FULL: Symbol
|
|
5
|
+
DEFAULT_I18N_SCOPE: Symbol
|
|
6
|
+
|
|
7
|
+
def self.setup_i18n!: () -> void
|
|
8
|
+
|
|
9
|
+
module Methods
|
|
10
|
+
VALID_FORMATS: Array[Symbol]
|
|
11
|
+
|
|
12
|
+
def duration_in_words: (untyped duration, ?Hash[Symbol, untyped] options) -> String
|
|
13
|
+
|
|
14
|
+
private
|
|
15
|
+
|
|
16
|
+
def parse_options: (Hash[Symbol, untyped] options) -> [untyped, Symbol]
|
|
17
|
+
|
|
18
|
+
def normalize_format: (untyped format) -> Symbol
|
|
19
|
+
|
|
20
|
+
def sentencify: (Hash[Symbol, untyped] parts, Symbol scope, untyped locale) -> String
|
|
21
|
+
|
|
22
|
+
def sentence_options: (Symbol scope, untyped locale) -> untyped
|
|
23
|
+
|
|
24
|
+
def raise_type_error: (untyped type) -> bot
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
module ActionView
|
|
29
|
+
module Helpers
|
|
30
|
+
module DurationHelper
|
|
31
|
+
include DurationInWords::Methods
|
|
32
|
+
|
|
33
|
+
def duration_in_words: (untyped duration, ?Hash[Symbol, untyped] options) -> String
|
|
34
|
+
end
|
|
35
|
+
end
|
|
4
36
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
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.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Syed Aslam
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: activesupport
|
|
@@ -16,28 +15,56 @@ dependencies:
|
|
|
16
15
|
requirements:
|
|
17
16
|
- - ">="
|
|
18
17
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '0'
|
|
18
|
+
version: '6.0'
|
|
20
19
|
type: :runtime
|
|
21
20
|
prerelease: false
|
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
22
|
requirements:
|
|
24
23
|
- - ">="
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '0'
|
|
25
|
+
version: '6.0'
|
|
27
26
|
- !ruby/object:Gem::Dependency
|
|
28
27
|
name: i18n
|
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
|
30
29
|
requirements:
|
|
31
30
|
- - "~>"
|
|
32
31
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: 1.12
|
|
32
|
+
version: '1.12'
|
|
34
33
|
type: :runtime
|
|
35
34
|
prerelease: false
|
|
36
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
36
|
requirements:
|
|
38
37
|
- - "~>"
|
|
39
38
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: 1.12
|
|
39
|
+
version: '1.12'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: bundler-audit
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '0'
|
|
47
|
+
type: :development
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0'
|
|
54
|
+
- !ruby/object:Gem::Dependency
|
|
55
|
+
name: racc
|
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - ">="
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '0'
|
|
61
|
+
type: :development
|
|
62
|
+
prerelease: false
|
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - ">="
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '0'
|
|
41
68
|
- !ruby/object:Gem::Dependency
|
|
42
69
|
name: rake
|
|
43
70
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -80,6 +107,20 @@ dependencies:
|
|
|
80
107
|
- - "~>"
|
|
81
108
|
- !ruby/object:Gem::Version
|
|
82
109
|
version: '1.21'
|
|
110
|
+
- !ruby/object:Gem::Dependency
|
|
111
|
+
name: rubocop-rake
|
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
|
113
|
+
requirements:
|
|
114
|
+
- - ">="
|
|
115
|
+
- !ruby/object:Gem::Version
|
|
116
|
+
version: '0'
|
|
117
|
+
type: :development
|
|
118
|
+
prerelease: false
|
|
119
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
120
|
+
requirements:
|
|
121
|
+
- - ">="
|
|
122
|
+
- !ruby/object:Gem::Version
|
|
123
|
+
version: '0'
|
|
83
124
|
- !ruby/object:Gem::Dependency
|
|
84
125
|
name: rubocop-rspec
|
|
85
126
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -110,6 +151,7 @@ files:
|
|
|
110
151
|
- LICENSE.txt
|
|
111
152
|
- README.md
|
|
112
153
|
- Rakefile
|
|
154
|
+
- duration_in_words.gemspec
|
|
113
155
|
- lib/duration_in_words.rb
|
|
114
156
|
- lib/duration_in_words/action_view/helpers/duration_helper.rb
|
|
115
157
|
- lib/duration_in_words/locales/de.yml
|
|
@@ -124,7 +166,7 @@ metadata:
|
|
|
124
166
|
homepage_uri: https://github.com/aslam/duration_in_words
|
|
125
167
|
source_code_uri: https://github.com/aslam/duration_in_words
|
|
126
168
|
changelog_uri: https://github.com/aslam/duration_in_words/blob/main/CHANGELOG.md
|
|
127
|
-
|
|
169
|
+
rubygems_mfa_required: 'true'
|
|
128
170
|
rdoc_options: []
|
|
129
171
|
require_paths:
|
|
130
172
|
- lib
|
|
@@ -139,8 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
139
181
|
- !ruby/object:Gem::Version
|
|
140
182
|
version: '0'
|
|
141
183
|
requirements: []
|
|
142
|
-
rubygems_version: 3.
|
|
143
|
-
signing_key:
|
|
184
|
+
rubygems_version: 3.7.2
|
|
144
185
|
specification_version: 4
|
|
145
186
|
summary: Report ActiveSupport::Duration in concise human readable formats.
|
|
146
187
|
test_files: []
|