Sha256: 964e22f2f97444ab247ed28df8b13febef78b90a6edd3f608cb401b6b5baf963

Contents?: true

Size: 971 Bytes

Versions: 1

Compression:

Stored size: 971 Bytes

Contents

# allow for optional configuration of RubyUnits
#
# Usage:
#
#     RubyUnits.configure do |config|
#       config.separator = false
#     end
module RubyUnits
  class << self
    attr_writer :configuration
  end

  def self.configuration
    @configuration ||= Configuration.new
  end

  def self.reset
    @configuration = Configuration.new
  end

  def self.configure
    yield configuration
  end

  # holds actual configuration values for RubyUnits
  class Configuration
    # 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.
    attr_reader :separator

    def initialize
      self.separator = true
    end

    def separator=(value)
      raise ArgumentError, "configuration 'separator' may only be true or false" unless value == true || value == false

      @separator = value ? ' ' : nil
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ruby-units-2.4.1 lib/ruby_units/configuration.rb