timerizer 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/timerizer.rb +27 -18
  2. metadata +2 -2
data/lib/timerizer.rb CHANGED
@@ -162,8 +162,8 @@ class RelativeTime
162
162
  def before(time)
163
163
  time = time.to_time - @seconds
164
164
 
165
- new_month = time.month - @months
166
- new_year = time.year
165
+ new_month = time.month - self.months
166
+ new_year = time.year - self.years
167
167
  while new_month < 1
168
168
  new_month += 12
169
169
  new_year -= 1
@@ -195,8 +195,8 @@ class RelativeTime
195
195
  def after(time)
196
196
  time = time.to_time + @seconds
197
197
 
198
- new_year = time.year
199
- new_month = time.month + @months
198
+ new_year = time.year + self.years
199
+ new_month = time.month + self.months
200
200
  while new_month > 12
201
201
  new_year += 1
202
202
  new_month -= 12
@@ -226,24 +226,33 @@ class RelativeTime
226
226
  count_method = plural
227
227
  superior_unit = @@units.keys.index(unit) + 1
228
228
 
229
- define_method(in_method) do
230
- if @@in_seconds.has_key?(unit)
231
- @seconds / @@in_seconds[unit]
232
- elsif @@in_months.has_key?(unit)
233
- @months / @@in_months[unit]
234
- end
229
+ if @@in_seconds.has_key? unit
230
+ class_eval %Q"
231
+ def #{in_method}
232
+ @seconds / #{@@in_seconds[unit]}
233
+ end
234
+ "
235
+ elsif @@in_months.has_key? unit
236
+ class_eval %Q"
237
+ def #{in_method}
238
+ @months / #{@@in_months[unit]}
239
+ end
240
+ "
235
241
  end
236
242
 
237
- define_method(count_method) do
238
- in_superior = "in_#{@@units.values[superior_unit]}"
239
- count_superior = @@units.keys[superior_unit]
243
+ in_superior = "in_#{@@units.values[superior_unit]}"
244
+ count_superior = @@units.keys[superior_unit]
245
+
240
246
 
241
- time = self.send(in_method)
242
- if @@units.length > superior_unit
243
- time -= self.send(in_superior).send(count_superior).send(in_method)
247
+ class_eval %Q"
248
+ def #{count_method}
249
+ time = self.#{in_method}
250
+ if @@units.length > #{superior_unit}
251
+ time -= self.#{in_superior}.#{count_superior}.#{in_method}
252
+ end
253
+ time
244
254
  end
245
- time
246
- end
255
+ "
247
256
  end
248
257
 
249
258
  # Average second-based units to month-based units.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timerizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -38,7 +38,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
38
38
  version: '0'
39
39
  requirements: []
40
40
  rubyforge_project:
41
- rubygems_version: 1.8.23
41
+ rubygems_version: 1.8.24
42
42
  signing_key:
43
43
  specification_version: 3
44
44
  summary: Rails time helpers... without the Rails