Sha256: 53074c8f8186ae8621ff23a38424466876f43d76f401ed84e0596d1e7b79bc88

Contents?: true

Size: 705 Bytes

Versions: 17

Compression:

Stored size: 705 Bytes

Contents

require "time_difference"

module RefinedTimeDifference
  refine(TimeDifference) do
    def humanize_higher_than(limit)
      limit_index = TimeDifference::TIME_COMPONENTS.index(limit)

      diff_parts = []
      in_general.each_with_index do |array, index|
        part, quantity = array
        next if (quantity <= 0) || (limit_index < index)
        part = part.to_s.humanize

        if quantity <= 1
          part = part.singularize
        end

        diff_parts << "#{quantity} #{part}"
      end

      last_part = (diff_parts.pop or "")
      if diff_parts.empty?
        return last_part
      else
        return [diff_parts.join(", "), last_part].join(" and ")
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
autowow-0.17.1 lib/autowow/time_difference.rb
autowow-0.17.0 lib/autowow/time_difference.rb
autowow-0.16.1 lib/autowow/time_difference.rb
autowow-0.16.0 lib/autowow/time_difference.rb
autowow-0.15.0 lib/autowow/time_difference.rb
autowow-0.12.1 lib/autowow/time_difference.rb
autowow-0.12.0 lib/autowow/time_difference.rb
autowow-0.11.2 lib/autowow/time_difference.rb
autowow-0.11.1 lib/autowow/time_difference.rb
autowow-0.11.0 lib/autowow/time_difference.rb
autowow-0.10.1 lib/autowow/time_difference.rb
autowow-0.9.6 lib/autowow/time_difference.rb
autowow-0.9.5 lib/autowow/time_difference.rb
autowow-0.9.4 lib/autowow/time_difference.rb
autowow-0.9.3 lib/autowow/time_difference.rb
autowow-0.9.2 lib/autowow/time_difference.rb
autowow-0.9.1 lib/autowow/time_difference.rb