to_duration 1.2.0 → 1.2.1
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/lib/to_duration.rb +6 -0
- data/lib/to_duration/duration.rb +10 -21
- data/lib/to_duration/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f666e8ee38f3e2774197a4efcb96cd72a3eb7a00b86acca35d931e919020a81
|
4
|
+
data.tar.gz: 68f533ca4678c8ee6352f034166bd2da22a42f7cfa950d59479326844b0cd725
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f7030a9d7454278dcbc104d307945788f707c1e244bd7c2d7b1869d9a161109af45936dbe12c245b1f031469b8ffe096955ad4cdd096e9f35e150db7a0d4b4d
|
7
|
+
data.tar.gz: fd4c42b2819ee1cdfdd00db2a92324f0406ac385876e713ffafc9b5d2ec780a90310b38d7fa55167a784183f8644188b3c38ba117e303e7813d24caf7ca21ad3
|
data/lib/to_duration.rb
CHANGED
data/lib/to_duration/duration.rb
CHANGED
@@ -49,27 +49,24 @@ module ToDuration
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def to_s(options = {})
|
52
|
-
return t('less_than_one_second') if seconds < 1
|
52
|
+
return ToDuration.t('less_than_one_second') if seconds < 1
|
53
53
|
|
54
|
-
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
units_to_s(to_units(options))
|
59
|
-
end
|
60
|
-
|
61
|
-
private
|
54
|
+
units = to_units(options).map do |k, v|
|
55
|
+
"#{v} #{ToDuration.t(k.to_s.chop, count: v)}"
|
56
|
+
end
|
62
57
|
|
63
|
-
|
64
|
-
|
58
|
+
units.join(', ').tap do |s|
|
59
|
+
s.gsub!(/,([^,]*)$/, " #{ToDuration.t('and')}\\1") if units.length > 1
|
60
|
+
end
|
65
61
|
end
|
66
62
|
|
67
|
-
def to_units(options)
|
63
|
+
def to_units(options = {})
|
64
|
+
options = { weeks: false }.merge!(options)
|
68
65
|
duration = Duration.new(seconds)
|
69
66
|
|
70
67
|
{}.tap do |units|
|
71
68
|
UNITS.keys.each do |k|
|
72
|
-
next if options[k] != true
|
69
|
+
next if options.key?(k) && options[k] != true
|
73
70
|
|
74
71
|
count = duration.public_send(k)
|
75
72
|
next if count.zero?
|
@@ -79,13 +76,5 @@ module ToDuration
|
|
79
76
|
end
|
80
77
|
end
|
81
78
|
end
|
82
|
-
|
83
|
-
def units_to_s(units)
|
84
|
-
units = units.map { |k, v| "#{v} #{t(k.to_s.chop, count: v)}" }
|
85
|
-
|
86
|
-
s = units.join(', ')
|
87
|
-
s.gsub!(/,([^,]*)$/, " #{t('and')}\\1") if units.length > 1
|
88
|
-
s
|
89
|
-
end
|
90
79
|
end
|
91
80
|
end
|
data/lib/to_duration/version.rb
CHANGED