lib/time_index.rb in vcs_ruby-1.1.14 vs lib/time_index.rb in vcs_ruby-1.1.15

- old
+ new

@@ -5,12 +5,27 @@ module VCSRuby class TimeIndex include Comparable attr_reader :total_seconds + def has_unified_integer? + version = RUBY_VERSION.split('.').collect(&:to_i) + + return (version[0] == 2 && version[1] >= 4) || version[0] > 2 + end + + # compatibilty fix + def is_integer? variable + if has_unified_integer? + return variable.instance_of?(Integer) + else + return variable.instance_of?(Fixnum) || variable.instance_of?(Bignum) + end + end + def initialize time_index = '' - if time_index.instance_of? Float or time_index.instance_of? Integer + if is_integer?(time_index) || time_index.instance_of?(Float) @total_seconds = time_index else @total_seconds = 0.0 @to_parse = time_index.strip @@ -64,19 +79,19 @@ def seconds @total_seconds.abs % 60 end def + operand - if operand.instance_of? Integer + if is_integer? operand TimeIndex.new @total_seconds + operand else TimeIndex.new @total_seconds + operand.total_seconds end end def - operand - if operand.instance_of? Integer + if is_integer? operand TimeIndex.new @total_seconds - operand else TimeIndex.new @total_seconds - operand.total_seconds end end @@ -84,10 +99,10 @@ def * operand TimeIndex.new total_seconds * operand end def / operand - if operand.instance_of? Integer + if is_integer? operand TimeIndex.new @total_seconds / operand else @total_seconds / operand.total_seconds end end