class RubyUnits::Configuration

holds actual configuration values for RubyUnits

Attributes

format[R]

The style of format to use by default when generating output. When set to ‘:exponential`, all units will be represented in exponential notation instead of using a numerator and denominator.

@!attribute [rw] format

@return [Symbol] the format to use when generating output (:rational or :exponential) (default: :rational)
separator[R]

Used to separate the scalar from the unit when generating output. A value of ‘true` will insert a single space, and `false` will prevent adding a space to the string representation of a unit.

@!attribute [rw] separator

@return [Boolean] whether to include a space between the scalar and the unit

Public Class Methods

new() click to toggle source
# File lib/ruby_units/configuration.rb, line 45
def initialize
  self.format = :rational
  self.separator = true
end

Public Instance Methods

format=(value) click to toggle source

Set the format to use when generating output. The ‘:rational` style will generate units string like `3 m/s^2` and the `:exponential` style will generate units like `3 m*s^-2`.

@param value [Symbol] the format to use when generating output (:rational or :exponential) @return [void]

# File lib/ruby_units/configuration.rb, line 66
def format=(value)
  raise ArgumentError, "configuration 'format' may only be :rational or :exponential" unless %i[rational exponential].include?(value)

  @format = value
end
separator=(value) click to toggle source

Use a space for the separator to use when generating output.

@param value [Boolean] whether to include a space between the scalar and the unit @return [void]

# File lib/ruby_units/configuration.rb, line 54
def separator=(value)
  raise ArgumentError, "configuration 'separator' may only be true or false" unless [true, false].include?(value)

  @separator = value ? " " : nil
end