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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e0b74fb2b1428b25bd58dd451ceb93073f58fa803c8f135a3d0661983dd07ab
4
- data.tar.gz: 6439cb0650d16395fa3ec21ce206e6c7e03fce4dacc9829c27e6bae3a6cc2782
3
+ metadata.gz: 53a9a76ccc79bc85bd8f85480e62c12783260c31c8a9dd658d2534f1485eb663
4
+ data.tar.gz: ed294f375f5d68a38c5665ee3766b171c4a26cde8c209ea9ea05be04333bd5bf
5
5
  SHA512:
6
- metadata.gz: ae86b0118a46b1a254d26d7bac7ce5376caaf30df65e76409326ccb8d771c0f511e1b113b126fe46ec424f25c1ca29519107c7d96cbd9384b0878eb7fbb1e9a0
7
- data.tar.gz: a453cdea084d270100a7c0f0cfa984f07b55c428787365e4c2a36ab733928ef1914d2eb663cd0a1ef149c7a1b759a2416ff595c38e044bcdd2dd74bd1ea798f1
6
+ metadata.gz: 900214bb1801e30866b551fe395bd8695a3d101c4abf919cbf3e1f9e237ccca5af3756cb037fbe5e954377c0b00694a1a5b9f9a52410f8874d76fbca130b962c
7
+ data.tar.gz: b82c111999a4ae3078f57bb028926b34bdd37075b02c9f7002d37b9736eb8bd9857932a1d52a73be06c5a931b5038935476678cd827739dffef3aa79e4435af1
data/CHANGELOG.md CHANGED
@@ -1,4 +1,21 @@
1
- ## [Unreleased]
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
@@ -9,4 +9,8 @@ require "rubocop/rake_task"
9
9
 
10
10
  RuboCop::RakeTask.new
11
11
 
12
+ require "bundler/audit/task"
13
+
14
+ Bundler::Audit::Task.new
15
+
12
16
  task default: %i[spec rubocop]
@@ -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"
@@ -37,7 +37,7 @@ de:
37
37
  other: '%{count} Monate'
38
38
  weeks:
39
39
  one: '%{count} Woche'
40
- other: '%{count} Wochen'
40
+ other: '%{count} Wochen'
41
41
  days:
42
42
  one: '%{count} Tag'
43
43
  other: '%{count} Tage'
@@ -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.to_s == "full" ? I18N_SCOPE_FULL : DEFAULT_I18N_SCOPE
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) }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DurationInWords
4
- VERSION = "0.3.1"
4
+ VERSION = "0.4.0"
5
5
  end
@@ -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
 
@@ -1,4 +1,36 @@
1
1
  module DurationInWords
2
2
  VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
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.3.1
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