lib/trackoid/reader_extender.rb in trackoid-0.3.0 vs lib/trackoid/reader_extender.rb in trackoid-0.3.1
- old
+ new
@@ -18,34 +18,38 @@
# # operation, we can additionaly sum the hourly
# # array and return a new ReaderExtender c.
#
class ReaderExtender
def initialize(number, hours)
- @number = number
+ @total = number
@hours = hours
end
def hourly
@hours
end
def to_s
- @number.to_s
+ @total.to_s
end
+ def to_f
+ @total.to_f
+ end
+
def ==(other)
- @number == other
+ @total == other
end
def <=>(other)
- @number <=> other
+ @total <=> other
end
def +(other)
- return @number + other unless other.is_a?(ReaderExtender)
+ return @total + other unless other.is_a?(ReaderExtender)
- @number = @number + other
+ @total = @total + other
@hours = @hours.zip(other.hourly).map!(&:sum)
self
end
# Solution proposed by Yehuda Katz in the following Stack Overflow:
@@ -53,10 +57,10 @@
#
# Basically we override our methods while proxying all missing methods
# to the underliying FixNum
#
def method_missing(name, *args, &blk)
- ret = @number.send(name, *args, &blk)
+ ret = @total.send(name, *args, &blk)
ret.is_a?(Numeric) ? ReaderExtender.new(ret, @hours) : ret
end
end
end