Sha256: 807ad1c942504d4b1bf8e25b2c49ea200b187b4d1ee55fc01698d55aa8eff068

Contents?: true

Size: 509 Bytes

Versions: 1

Compression:

Stored size: 509 Bytes

Contents

module FormattedLength
  def self.format_to_s(value)
    value = value || 0
    hours = value / 3600
    minutes = (value / 60) % 60
    seconds = value % 60
    result = "%02d" % minutes + ":%02d" % seconds
    result = "#{hours}:#{result}" if hours > 0
    result
  end

  def self.format_to_i(value)
    result = 0
    unless value.nil?
      if (match = /((\d+):)?(\d+):(\d+)/.match(value))
        result = match[2].to_i * 3600 + match[3].to_i * 60 + match[4].to_i
      end
    end
    result
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
formatted_length-0.0.7 lib/formatted_length/formatted_length.rb