Sha256: 45e4444c54eb70fa1ec7c31a4f5f1c1958a7c0ef2f502d9b0fdd20499b3f65c1

Contents?: true

Size: 643 Bytes

Versions: 2

Compression:

Stored size: 643 Bytes

Contents

module Medidas
  class Unit
    attr_reader :base_unit

    def self.registered_units
      @registered_units ||= {}
    end

    def *(number)
      Measure.for(amount: number, unit: self)
    end

    def base_unit?(a_unit)
      a_unit == base_unit
    end

    def to_s
      @name
    end

    def inspect
      "#{self.class}(#{@name})"
    end

    def coerce(amount)
      raise TypeError, "Unit can't be coerced into Integer except for multiplication" unless caller.first.include?("`*'")

      [self, amount]
    end

    def name_for(amount)
      if amount == 1
        @name
      else
        @plural
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
medidas-0.1.1 lib/medidas/unit.rb
medidas-0.1.0 lib/medidas/unit.rb