Sha256: fb6ccad9e776bdfb4fa7bf80a3e3cd12f785ff4e8fdfa7d873d2957952a4f001

Contents?: true

Size: 701 Bytes

Versions: 10

Compression:

Stored size: 701 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 or 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

10 entries across 10 versions & 1 rubygems

Version Path
autowow-0.8.0 lib/autowow/time_difference.rb
autowow-0.7.0 lib/autowow/time_difference.rb
autowow-0.6.3 lib/autowow/time_difference.rb
autowow-0.6.0 lib/autowow/time_difference.rb
autowow-0.5.0 lib/autowow/time_difference.rb
autowow-0.4.1 lib/autowow/time_difference.rb
autowow-0.4.0 lib/autowow/time_difference.rb
autowow-0.3.0 lib/autowow/time_difference.rb
autowow-0.2.0 lib/autowow/time_difference.rb
autowow-0.1.0 lib/autowow/time_difference.rb