Sha256: 5e7137fc4cccf5634685e9394cf66c61dead4f5e3fd802c4fe8dbe4e373c602a

Contents?: true

Size: 705 Bytes

Versions: 1

Compression:

Stored size: 705 Bytes

Contents

module DuckPuncher
  module Numeric
    def to_currency
      '%.2f' % self.round(2)
    end

    def to_duration(seconds=false)
      secs = self.to_i
      mins = secs / 60
      hours = mins / 60
      buffer = ''
      if hours > 0
        num_mins = mins % 60
        buffer << "#{hours} h"
        buffer << " #{num_mins} min" unless num_mins.zero?
      elsif mins > 0
        num_secs = secs % 60
        buffer << "#{mins} min"
        buffer << " #{num_secs} s" if seconds && num_secs.nonzero?
      elsif seconds && secs >= 0
        buffer << "#{secs} s"
      end
      buffer
    end

    def to_rad
      self / 180 * Math::PI
    end
  end
end

Numeric.send(:include, DuckPuncher::Numeric)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
duck_puncher-0.0.4 lib/duck_puncher/numeric.rb