Sha256: f0b321a1c4af045cd1bc0a01db41e2f77119d2e4b9fa9ca7afcf733d3d340816

Contents?: true

Size: 1016 Bytes

Versions: 6

Compression:

Stored size: 1016 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.
    # set to nil to prevent adding a space to the string representation of a unit
    # separators other than ' ' and '' may work, but you may encounter problems
    attr_reader :separator

    def initialize
      self.separator = true
    end

    def separator=(value)
      raise ArgumentError, "configuration 'separator' may only be true or false" unless value.class == TrueClass || value.class == FalseClass
      @separator = value ? ' ' : nil
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ruby-units-2.3.2 lib/ruby_units/configuration.rb
ruby-units-2.3.1 lib/ruby_units/configuration.rb
ruby-units-2.3.0 lib/ruby_units/configuration.rb
ruby-units-2.2.1 lib/ruby_units/configuration.rb
ruby-units-2.2.0 lib/ruby_units/configuration.rb
ruby-units-2.1.0 lib/ruby_units/configuration.rb