lib/rafini/odometers.rb
# Integer#sec2time
# Returns a struct with the different time scales for number of seconds.
#   10_000.sec2time.to_s #=> "2 hours and 46 minutes"
#   10_000.sec2time.hour #=> 2
Integer#sec2time
Returns a struct with the different time scales for number of seconds.
Integer#sec2time Returns a struct with the different time scales for number of seconds .
def sec2time
        odoread(SEC2TIME, factors:false) do
          def to_s
            string = nil
            SEC2TIME.keys.reverse_each do |key|
              count=self[key]
              if string
                if count > 0
                  string << " and #{count} #{key}"
                  string << 's' if count > 1
                end
                break
              end
              next if count==0
              string = "#{count} #{key}"
              string << 's' if count > 1
            end
            string = "0 #{SEC2TIME.first[0]}s" unless string
            string
          end
          def to_i
            SEC2TIME.to_a.map{|k,v|v*self[k]}.sum.round
          end
        end
      end
def sec2time odoread ( SEC2TIME , factors : false ) do def to_s string = nil SEC2TIME . keys . reverse_each do | key | count = self [ key ] if string if count > 0 string << " and #{count} #{key}" string << 's' if count > 1 end break end next if count == 0 string = "#{count} #{key}" string << 's' if count > 1 end string = "0 #{SEC2TIME.first[0]}s" unless string string end def to_i SEC2TIME . to_a . map { | k , v | v * self [ k ] } . sum . round end end end
Integer#sec2time
Returns a struct with the different time scales for number of seconds.
Integer#sec2time Returns a struct with the different time scales for number of seconds .