lib/fugit/duration.rb in fugit-1.1.2 vs lib/fugit/duration.rb in fugit-1.1.3

- old
+ new

@@ -126,22 +126,22 @@ KEYS.inject(0) { |s, (k, a)| v = @h[k]; next s unless v; s += v * a[:s] } end def inflate - h = + params = @h.inject({ sec: 0 }) { |h, (k, v)| a = KEYS[k] if a[:I] h[:sec] += (v * a[:s]) else h[k] = v end h } - self.class.allocate.init(@original, {}, h) + self.class.allocate.init(@original, {}, params) end # Round float seconds to 9 decimals when deflating # SECOND_ROUND = 9 @@ -182,13 +182,13 @@ self.class.allocate.init(@original, {}, h) end def opposite - h = @h.inject({}) { |h, (k, v)| h[k] = -v; h } + params = @h.inject({}) { |h, (k, v)| h[k] = -v; h } - self.class.allocate.init(nil, {}, h) + self.class.allocate.init(nil, {}, params) end alias -@ opposite def add_numeric(n) @@ -199,13 +199,13 @@ self.class.allocate.init(nil,{}, h) end def add_duration(d) - h = d.h.inject(@h.dup) { |h, (k, v)| h[k] = (h[k] || 0) + v; h } + params = d.h.inject(@h.dup) { |h, (k, v)| h[k] = (h[k] || 0) + v; h } - self.class.allocate.init(nil, {}, h) + self.class.allocate.init(nil, {}, params) end def add_to_time(t) t = ::EtOrbi.make_time(t) @@ -310,13 +310,13 @@ def self.common_rewrite_dur(t) t .subgather(nil) - .inject({}) { |h, t| - v = t.string; v = v.index('.') ? v.to_f : v.to_i + .inject({}) { |h, tt| + v = tt.string; v = v.index('.') ? v.to_f : v.to_i # drops ending ("y", "m", ...) by itself - h[t.name] = (h[t.name] || 0) + v + h[tt.name] = (h[tt.name] || 0) + v h } end module Parser include Raabro