timerizer 0.1.4 → 0.2.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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/timerizer.rb +63 -37
  3. metadata +6 -8
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f23581978647a19fcd4536615da3394b0c61e033
4
+ data.tar.gz: 69f149f7310a57fd7fe401f2f20dd1a823986ce5
5
+ SHA512:
6
+ metadata.gz: c3baba0ecac98dcf2a95d43fbd6b18f281a2b2eafd0eecf42cc528de28d1aaa9074bdb2a66bec85590dfe4b30fb9cb7a54e236d35fd2fc59b205ad8255821e14
7
+ data.tar.gz: 39de4ac9fec51a58bc4e5ba43f78d397a39cec81ceaa99fac1506c47278d22b74d45de0f35f297a8a929a718948ee266480265e0cf8847d28a996e1242145d52
data/lib/timerizer.rb CHANGED
@@ -103,10 +103,10 @@ class RelativeTime
103
103
  # Initialize a new instance of RelativeTime.
104
104
  # @overload new(hash)
105
105
  # @param [Hash] units The base units to initialize with
106
- # @option units [Fixnum] :seconds The number of seconds
107
- # @option units [Fixnum] :months The number of months
106
+ # @option units [Integer] :seconds The number of seconds
107
+ # @option units [Integer] :months The number of months
108
108
  # @overload new(count, unit)
109
- # @param [Fixnum] count The number of units to initialize with
109
+ # @param [Integer] count The number of units to initialize with
110
110
  # @param [Symbol] unit The unit to initialize. See {RelativeTime#units}
111
111
  def initialize(count = 0, unit = :second)
112
112
  if count.is_a? Hash
@@ -138,7 +138,7 @@ class RelativeTime
138
138
 
139
139
  # Return the number of base units in a RelativeTime.
140
140
  # @param [Symbol] unit The unit to return, either :seconds or :months
141
- # @return [Fixnum] The requested unit count
141
+ # @return [Integer] The requested unit count
142
142
  # @raise [ArgumentError] Unit requested was not :seconds or :months
143
143
  def get(unit)
144
144
  if unit == :seconds
@@ -227,13 +227,13 @@ class RelativeTime
227
227
  superior_unit = @@units.keys.index(unit) + 1
228
228
 
229
229
  if @@in_seconds.has_key? unit
230
- class_eval %Q"
230
+ class_eval "
231
231
  def #{in_method}
232
232
  @seconds / #{@@in_seconds[unit]}
233
233
  end
234
234
  "
235
235
  elsif @@in_months.has_key? unit
236
- class_eval %Q"
236
+ class_eval "
237
237
  def #{in_method}
238
238
  @months / #{@@in_months[unit]}
239
239
  end
@@ -244,7 +244,7 @@ class RelativeTime
244
244
  count_superior = @@units.keys[superior_unit]
245
245
 
246
246
 
247
- class_eval %Q"
247
+ class_eval "
248
248
  def #{count_method}
249
249
  time = self.#{in_method}
250
250
  if @@units.length > #{superior_unit}
@@ -344,7 +344,7 @@ class RelativeTime
344
344
  # @overload to_s(hash)
345
345
  # @param [Hash] hash The custom hash to use
346
346
  # @option hash [Hash] :units The unit names to use. See @@syntaxes for examples
347
- # @option hash [Fixnum] :count The maximum number of units to output. `1` would output only the unit of greatest example (such as the hour value in `1.hour 3.minutes 2.seconds`).
347
+ # @option hash [Integer] :count The maximum number of units to output. `1` would output only the unit of greatest example (such as the hour value in `1.hour 3.minutes 2.seconds`).
348
348
  # @option hash [String] :separator The separator to use in between a unit and its value
349
349
  # @option hash [String] :delimiter The delimiter to use in between different unit-value pairs
350
350
  # @example
@@ -402,24 +402,24 @@ class WallClock
402
402
  # Initialize a new instance of WallClock
403
403
  # @overload new(hash)
404
404
  # @param [Hash] units The units to initialize with
405
- # @option units [Fixnum] :hour The hour to initialize with
406
- # @option units [Fixnum] :minute The minute to initialize with
407
- # @option units [Fixnum] :second The second to initialize with
405
+ # @option units [Integer] :hour The hour to initialize with
406
+ # @option units [Integer] :minute The minute to initialize with
407
+ # @option units [Integer] :second The second to initialize with
408
408
  # @overload new(hour, minute, meridiem)
409
- # @param [Fixnum] hour The hour to initialize with
410
- # @param [Fixnum] minute The minute to initialize with
409
+ # @param [Integer] hour The hour to initialize with
410
+ # @param [Integer] minute The minute to initialize with
411
411
  # @param [Symbol] meridiem The meridiem to initialize with (`:am` or `:pm`)
412
412
  # @overload new(hour, minute, second, meridiem)
413
- # @param [Fixnum] hour The hour to initialize with
414
- # @param [Fixnum] minute The minute to initialize with
415
- # @param [Fixnum] second The second to initialize with
413
+ # @param [Integer] hour The hour to initialize with
414
+ # @param [Integer] minute The minute to initialize with
415
+ # @param [Integer] second The second to initialize with
416
416
  # @param [Symbol] meridiem The meridiem to initialize with (`:am` or `:pm`)
417
417
  # @overload new(seconds)
418
- # @param [Fixnum] seconds The number of seconds to initialize with (for use with #to_i)
418
+ # @param [Integer] seconds The number of seconds to initialize with (for use with #to_i)
419
419
  # @raise InvalidMeridiemError Meridiem is not `:am` or `:pm`
420
420
  def initialize(hour = nil, minute = nil, second = 0, meridiem = :am)
421
421
  units = nil
422
- if hour.is_a?(Fixnum) && minute.nil?
422
+ if hour.is_a?(Integer) && minute.nil?
423
423
  units = {:second => hour}
424
424
  elsif hour.is_a?(Hash)
425
425
  units = hour
@@ -494,38 +494,38 @@ class WallClock
494
494
  end
495
495
 
496
496
  # Get the time of the WallClock, in seconds
497
- # @return [Fixnum] The total time of the WallClock, in seconds
497
+ # @return [Integer] The total time of the WallClock, in seconds
498
498
  def in_seconds
499
499
  @seconds
500
500
  end
501
501
 
502
502
  # Get the time of the WallClock, in minutes
503
- # @return [Fixnum] The total time of the WallClock, in minutes
503
+ # @return [Integer] The total time of the WallClock, in minutes
504
504
  def in_minutes
505
505
  @seconds / RelativeTime.units_in_seconds[:minute]
506
506
  end
507
507
 
508
508
  # Get the time of the WallClock, in hours
509
- # @return [Fixnum] The total time of the WallClock, in hours
509
+ # @return [Integer] The total time of the WallClock, in hours
510
510
  def in_hours
511
511
  @seconds / RelativeTime.units_in_seconds[:hour]
512
512
  end
513
513
 
514
514
  # Get the second of the WallClock.
515
- # @return [Fixnum] The second component of the WallClock
515
+ # @return [Integer] The second component of the WallClock
516
516
  def second
517
517
  self.to_relative.seconds
518
518
  end
519
519
 
520
520
  # Get the minute of the WallClock.
521
- # @return [Fixnum] The minute component of the WallClock
521
+ # @return [Integer] The minute component of the WallClock
522
522
  def minute
523
523
  self.to_relative.minutes
524
524
  end
525
525
 
526
526
  # Get the hour of the WallClock.
527
527
  # @param [Symbol] system The houring system to use (either `:twelve_hour` or `:twenty_four_hour`; default `:twenty_four_hour`)
528
- # @return [Fixnum] The hour component of the WallClock
528
+ # @return [Integer] The hour component of the WallClock
529
529
  def hour(system = :twenty_four_hour)
530
530
  hour = self.to_relative.hours
531
531
  if system == :twelve_hour
@@ -624,21 +624,45 @@ class Time
624
624
  # @see #since
625
625
  class TimeIsInTheFutureError < ArgumentError; end
626
626
 
627
- add = instance_method(:+)
628
- define_method(:+) do |time|
627
+ class << self
628
+ alias_method :classic_new, :new
629
+
630
+ def new(*args)
631
+ begin
632
+ Time.classic_new(*args)
633
+ rescue ArgumentError
634
+ if args.empty?
635
+ Time.new
636
+ else
637
+ Time.local(*args)
638
+ end
639
+ end
640
+ end
641
+ end
642
+
643
+ # def initialize(*args)
644
+ # self.classic_new(args)
645
+ # # if args.count == 0
646
+
647
+ # # else
648
+ # # end
649
+ # end
650
+
651
+ alias_method :add, :+
652
+ def +(time)
629
653
  if time.is_a? RelativeTime
630
654
  time.after(self)
631
655
  else
632
- add.bind(self).(time)
656
+ self.add(time)
633
657
  end
634
658
  end
635
659
 
636
- subtract = instance_method(:-)
637
- define_method(:-) do |time|
660
+ alias_method :subtract, :-
661
+ def -(time)
638
662
  if time.is_a? RelativeTime
639
663
  time.before(self)
640
664
  else
641
- subtract.bind(self).(time)
665
+ self.subtract(time)
642
666
  end
643
667
  end
644
668
 
@@ -718,7 +742,7 @@ end
718
742
  # {Date} class monkeywrenched with {RelativeTime} helpers.
719
743
  class Date
720
744
  # Return the number of days in a given month.
721
- # @return [Fixnum] Number of days in the month of the {Date}.
745
+ # @return [Integer] Number of days in the month of the {Date}.
722
746
  # @example
723
747
  # Date.new(2000, 2).days_in_month
724
748
  # => 29
@@ -759,17 +783,19 @@ class Date
759
783
  end
760
784
  end
761
785
 
762
- # Monkeywrenched {Fixnum} class enabled to return {RelativeTime} objects.
786
+ # Monkeywrenched {Integer} class enabled to return {RelativeTime} objects.
763
787
  # @example
764
788
  # 5.minutes
765
789
  # => 5 minutes
766
790
  # @see {RelativeTime#units}
767
- class Fixnum
791
+ class Integer
768
792
  RelativeTime.units.each do |unit, plural|
769
- define_method(unit) do |added_time = RelativeTime.new|
770
- time = RelativeTime.new(self, unit)
771
- time + added_time
772
- end
793
+ class_eval "
794
+ def #{unit}(added_time = RelativeTime.new)
795
+ time = RelativeTime.new(self, :#{unit})
796
+ time + added_time unless added_time.nil?
797
+ end
798
+ "
773
799
  alias_method(plural, unit)
774
800
  end
775
801
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timerizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
5
- prerelease:
4
+ version: 0.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Kyle Lacy
@@ -20,27 +19,26 @@ files:
20
19
  - lib/timerizer.rb
21
20
  homepage: http://github.com/kylewlacy/timerizer
22
21
  licenses: []
22
+ metadata: {}
23
23
  post_install_message:
24
24
  rdoc_options: []
25
25
  require_paths:
26
26
  - lib
27
27
  required_ruby_version: !ruby/object:Gem::Requirement
28
- none: false
29
28
  requirements:
30
- - - ! '>='
29
+ - - ">="
31
30
  - !ruby/object:Gem::Version
32
31
  version: '0'
33
32
  required_rubygems_version: !ruby/object:Gem::Requirement
34
- none: false
35
33
  requirements:
36
- - - ! '>='
34
+ - - ">="
37
35
  - !ruby/object:Gem::Version
38
36
  version: '0'
39
37
  requirements: []
40
38
  rubyforge_project:
41
- rubygems_version: 1.8.24
39
+ rubygems_version: 2.4.5.1
42
40
  signing_key:
43
- specification_version: 3
41
+ specification_version: 4
44
42
  summary: Rails time helpers... without the Rails
45
43
  test_files: []
46
44
  has_rdoc: