Sha256: fbff02373a1b7c93174dd5575ec0fc0e2cbc0fe42e29befe974d40fc86923d93
Contents?: true
Size: 843 Bytes
Versions: 20
Compression:
Stored size: 843 Bytes
Contents
# -*- encoding: utf-8 -*- # -*- frozen_string_literal: true -*- # -*- warn_indent: true -*- module UnitMeasurements module Formatter # The default format for formatting measurements. DEFAULT_FORMAT = "%.2<quantity>f %<unit>s".freeze # Formats measurement to certain formatted string specified by +format+. # If +format+ is not specified, it uses +DEFAULT_FORMAT+ for # formatting the measurement # # @example # UnitMeasurements::Weight.parse("2 kg").to(:st).format # => "0.31 st" # UnitMeasurements::Weight.parse("2 kg").to(:st).format("%.4<quantity>f %<unit>s") # => "0.3149 st" # # @param [String] format # # @return [String] def format(format = nil) kwargs = {quantity: quantity, unit: unit.to_s} (format || DEFAULT_FORMAT) % kwargs end end end
Version data entries
20 entries across 20 versions & 1 rubygems