Sha256: 0d1dd85c319d4a6a4f35f233df4791ccff6a71d5298212fcd7cc8e1c13c50949

Contents?: true

Size: 753 Bytes

Versions: 12

Compression:

Stored size: 753 Bytes

Contents

class Numeric
  module Units
    Sec        = 1
    Min        = Sec     * 60
    Hour       = Min     * 60
    Day        = Hour    * 24
    Week       = Day     * 7
    Month      = Week    * 4
    Year       = Day     * 365
    Decade     = Year    * 10
    Century    = Decade  * 10
    Millennium = Century * 10
    Eon        = 1.0/0
  end

  def seconds_in_words
    unit = get_unit(self)
    unit_difference = self / Units.const_get(unit.capitalize)
    unit = unit.to_s.downcase + ('s' if self > 1)
    "#{unit_difference.to_i} #{unit}"
  end

  private
  def get_unit(time_difference)
    Units.constants.each_cons(2) do |con|
      return con.first if (Units.const_get(con[0])...Units.const_get(con[1])) === time_difference
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
redpomo-0.0.12 lib/redpomo/numeric_ext.rb
redpomo-0.0.11 lib/redpomo/numeric_ext.rb
redpomo-0.0.10 lib/redpomo/numeric_ext.rb
redpomo-0.0.9 lib/redpomo/numeric_ext.rb
redpomo-0.0.8 lib/redpomo/numeric_ext.rb
redpomo-0.0.7 lib/redpomo/numeric_ext.rb
redpomo-0.0.6 lib/redpomo/numeric_ext.rb
redpomo-0.0.5 lib/redpomo/numeric_ext.rb
redpomo-0.0.4 lib/redpomo/numeric_ext.rb
redpomo-0.0.3 lib/redpomo/numeric_ext.rb
redpomo-0.0.2 lib/redpomo/numeric_ext.rb
redpomo-0.0.1 lib/redpomo/numeric_ext.rb