Sha256: 61639bceb19a1c1e1ac5ad31952c9652ef3925c64c818b0502dd89bc78a9891d

Contents?: true

Size: 1016 Bytes

Versions: 2

Compression:

Stored size: 1016 Bytes

Contents

require 'extensional'

module UOM
  # Dimension enumerates the standard Unit dimensions. These consist of the seven physical International System of Units
  # SI base unit dimensions and an INFORMATION dimension for representing computer storage.
  class Dimension
    attr_accessor :label

    def initialize(label)
      @label = label
    end

    def to_s
      @label
    end
  end

  # A CompositeDimension combines dimensions with an operator.
  class CompositeDimension < Dimension
    make_extensional(Hash.new { |hash, spec| new(*spec) }) { |hash, dim| hash[dim.dimensions + [dim.operator]] = dim }

    attr_reader :dimensions, :operator

    # Creates a CompositeDimension from the given dimensions and operator symbol
    def initialize(dimensions, operator)
      @dimensions = dimensions
      @operator = operator
      super(create_label)
      # add to the extent
      CompositeDimension << self
    end

    private

    def create_label
      @dimensions.join("_#{@operator}_")
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
uom-1.2.2 lib/uom/dimension.rb
uom-1.2.1 lib/uom/dimension.rb