Sha256: 504c8663c07ad2d142a2edeeb8ce46305f458f3f9ad613c9f18e04f342147650

Contents?: true

Size: 847 Bytes

Versions: 1

Compression:

Stored size: 847 Bytes

Contents

module Unitwise
  class Scale
    attr_reader :value

    include Unitwise::Composable

    def initialize(value, unit)
      @value = value
      if unit.is_a?(Unit)
        @unit = unit.dup
      else
        @unit = Unit.new(unit.to_s)
      end
    end

    def dup
      self.class.new(value, unit)
    end

    def atoms
      unit.atoms
    end

    def special?
      unit.special?
    end

    def functional(value, direction=1)
      unit.functional(value, direction)
    end

    def scalar
      value * unit.scalar
    end

    def unit
      @unit ||= Unit.new(@unit_code)
    end

    def root_terms
      unit.root_terms
    end

    def depth
      unit.depth + 1
    end

    def terminal?
      depth <= 3
    end

    def to_s
      "#{value} #{unit}"
    end

    def inspect
      "<#{self.class} #{to_s}>"
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
unitwise-0.1.0 lib/unitwise/scale.rb