lib/flapjack/utility.rb in flapjack-0.7.14 vs lib/flapjack/utility.rb in flapjack-0.7.15

- old
+ new

@@ -5,14 +5,14 @@ def time_period_in_words(period) period_mm, period_ss = period.divmod(60) period_hh, period_mm = period_mm.divmod(60) period_dd, period_hh = period_hh.divmod(24) - ["#{period_dd} days", - "#{period_hh} hours", - "#{period_mm} minutes", - "#{period_ss} seconds"].reject {|s| s =~ /^0 /}.join(', ') + ["#{period_dd} day#{plural_s(period_dd)}", + "#{period_hh} hour#{plural_s(period_hh)}", + "#{period_mm} minute#{plural_s(period_mm)}", + "#{period_ss} second#{plural_s(period_ss)}"].reject {|s| s =~ /^0 /}.join(', ') end # Returns relative time in words referencing the given date # relative_time_ago(Time.now) => 'about a minute ago' def relative_time_ago(from_time) @@ -64,9 +64,15 @@ # is all that's needed, but for Ruby 1.8 compatability, these must # be flattened and the resulting array unpacked. flatten(1) only # flattens the arrays constructed in the block, it won't mess up # any values (or keys) that are themselves arrays/hashes. Hash[ *( key_value_pairs.flatten(1) )] + end + + private + + def plural_s(value) + (value == 1) ? '' : 's' end end end