duration_in_words 0.3.1 → 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/CHANGELOG.md +18 -1
- data/Rakefile +4 -0
- data/duration_in_words.gemspec +1 -0
- data/lib/duration_in_words/locales/de.yml +1 -1
- data/lib/duration_in_words/methods.rb +13 -2
- data/lib/duration_in_words/version.rb +1 -1
- data/lib/duration_in_words.rb +0 -1
- data/sig/duration_in_words.rbs +33 -1
- metadata +15 -1
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/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,21 @@
|
|
|
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.
|
|
2
19
|
|
|
3
20
|
## [0.3.1] - 2026-03-28
|
|
4
21
|
|
data/Rakefile
CHANGED
data/duration_in_words.gemspec
CHANGED
|
@@ -34,6 +34,7 @@ Gem::Specification.new do |spec|
|
|
|
34
34
|
spec.add_dependency "activesupport", ">= 6.0"
|
|
35
35
|
spec.add_dependency "i18n", "~> 1.12"
|
|
36
36
|
|
|
37
|
+
spec.add_development_dependency "bundler-audit"
|
|
37
38
|
spec.add_development_dependency "racc"
|
|
38
39
|
spec.add_development_dependency "rake", "~> 13.0"
|
|
39
40
|
spec.add_development_dependency "rspec", "~> 3.0"
|
|
@@ -4,6 +4,8 @@ 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
|
|
|
@@ -18,14 +20,23 @@ module DurationInWords
|
|
|
18
20
|
private
|
|
19
21
|
|
|
20
22
|
def parse_options(options)
|
|
21
|
-
format = options.fetch(:format, :compact)
|
|
23
|
+
format = normalize_format(options.fetch(:format, :compact))
|
|
22
24
|
locale = options.fetch(:locale, I18n.locale)
|
|
23
25
|
|
|
24
|
-
scope = format
|
|
26
|
+
scope = format == :full ? I18N_SCOPE_FULL : DEFAULT_I18N_SCOPE
|
|
25
27
|
|
|
26
28
|
[locale, scope]
|
|
27
29
|
end
|
|
28
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
|
+
|
|
29
40
|
def sentencify(parts, scope, locale)
|
|
30
41
|
parts
|
|
31
42
|
.sort_by { |unit, _| ActiveSupport::Duration::PARTS.index(unit) }
|
data/lib/duration_in_words.rb
CHANGED
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,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.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Syed Aslam
|
|
@@ -37,6 +37,20 @@ dependencies:
|
|
|
37
37
|
- - "~>"
|
|
38
38
|
- !ruby/object:Gem::Version
|
|
39
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'
|
|
40
54
|
- !ruby/object:Gem::Dependency
|
|
41
55
|
name: racc
|
|
42
56
|
requirement: !ruby/object:Gem::Requirement
|