ruby-duration 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/duration.rb +13 -6
  2. data/lib/duration/version.rb +1 -1
  3. metadata +2 -13
data/lib/duration.rb CHANGED
@@ -146,11 +146,12 @@ class Duration
146
146
  'H' => @hours.to_s.rjust(2, '0'),
147
147
  'M' => @minutes.to_s.rjust(2, '0'),
148
148
  'S' => @seconds.to_s.rjust(2, '0'),
149
- '~s' => @seconds == 1 ? I18n.t(:second, :scope => :ruby_duration, :default => "second") : I18n.t(:seconds, :scope => :ruby_duration, :default => "seconds"),
150
- '~m' => @minutes == 1 ? I18n.t(:minute, :scope => :ruby_duration, :default => "minute") : I18n.t(:minutes, :scope => :ruby_duration, :default => "minutes"),
151
- '~h' => @hours == 1 ? I18n.t(:hour, :scope => :ruby_duration, :default => "hour") : I18n.t(:hours, :scope => :ruby_duration, :default => "hours"),
152
- '~d' => @days == 1 ? I18n.t(:day, :scope => :ruby_duration, :default => "day") : I18n.t(:days, :scope => :ruby_duration, :default => "days"),
153
- '~w' => @weeks == 1 ? I18n.t(:week, :scope => :ruby_duration, :default => "week") : I18n.t(:weeks, :scope => :ruby_duration, :default => "weeks")}
149
+ '~s' => i18n_for(:second),
150
+ '~m' => i18n_for(:minute),
151
+ '~h' => i18n_for(:hour),
152
+ '~d' => i18n_for(:day),
153
+ '~w' => i18n_for(:week)
154
+ }
154
155
 
155
156
  format_str.gsub(/%?%(w|d|h|m|s|t|H|M|S|~(?:s|m|h|d|w))/) do |match|
156
157
  match['%%'] ? match : identifiers[match[1..-1]]
@@ -178,5 +179,11 @@ private
178
179
  # Gather the divided units
179
180
  @weeks, @days, @hours, @minutes, @seconds = units
180
181
  end
181
-
182
+
183
+ def i18n_for(singular)
184
+ plural = "#{singular}s"
185
+ label = send(plural) == 1 ? singular : plural
186
+
187
+ I18n.t(label, :scope => :ruby_duration, :default => label.to_s)
188
+ end
182
189
  end
@@ -1,3 +1,3 @@
1
1
  class Duration
2
- VERSION = "0.5.2"
2
+ VERSION = "0.5.3"
3
3
  end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-duration
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 5
9
- - 2
10
- version: 0.5.2
8
+ - 3
9
+ version: 0.5.3
11
10
  platform: ruby
12
11
  authors:
13
12
  - Jose Peleteiro
@@ -27,7 +26,6 @@ dependencies:
27
26
  requirements:
28
27
  - - ">="
29
28
  - !ruby/object:Gem::Version
30
- hash: 3
31
29
  segments:
32
30
  - 0
33
31
  version: "0"
@@ -41,7 +39,6 @@ dependencies:
41
39
  requirements:
42
40
  - - ">="
43
41
  - !ruby/object:Gem::Version
44
- hash: 23
45
42
  segments:
46
43
  - 1
47
44
  - 0
@@ -57,7 +54,6 @@ dependencies:
57
54
  requirements:
58
55
  - - ">="
59
56
  - !ruby/object:Gem::Version
60
- hash: 3
61
57
  segments:
62
58
  - 0
63
59
  version: "0"
@@ -71,7 +67,6 @@ dependencies:
71
67
  requirements:
72
68
  - - ">="
73
69
  - !ruby/object:Gem::Version
74
- hash: 3
75
70
  segments:
76
71
  - 0
77
72
  version: "0"
@@ -85,7 +80,6 @@ dependencies:
85
80
  requirements:
86
81
  - - ">="
87
82
  - !ruby/object:Gem::Version
88
- hash: 3
89
83
  segments:
90
84
  - 0
91
85
  version: "0"
@@ -99,7 +93,6 @@ dependencies:
99
93
  requirements:
100
94
  - - ">="
101
95
  - !ruby/object:Gem::Version
102
- hash: 7
103
96
  segments:
104
97
  - 3
105
98
  - 0
@@ -115,7 +108,6 @@ dependencies:
115
108
  requirements:
116
109
  - - ">="
117
110
  - !ruby/object:Gem::Version
118
- hash: 25
119
111
  segments:
120
112
  - 0
121
113
  - 3
@@ -131,7 +123,6 @@ dependencies:
131
123
  requirements:
132
124
  - - ">="
133
125
  - !ruby/object:Gem::Version
134
- hash: 25
135
126
  segments:
136
127
  - 0
137
128
  - 3
@@ -180,7 +171,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
180
171
  requirements:
181
172
  - - ">="
182
173
  - !ruby/object:Gem::Version
183
- hash: 3
184
174
  segments:
185
175
  - 0
186
176
  version: "0"
@@ -189,7 +179,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
179
  requirements:
190
180
  - - ">="
191
181
  - !ruby/object:Gem::Version
192
- hash: 23
193
182
  segments:
194
183
  - 1
195
184
  - 3