Sha256: f5a894986083a124f479d10c1acd88075e4449637d0d97484e6a07b04cb251cc

Contents?: true

Size: 1.3 KB

Versions: 52

Compression:

Stored size: 1.3 KB

Contents

Quantified
==========

Pretty quantifiable measurements which feel like ActiveSupport::Duration.

Access whichever included attributes you want like so:

    require 'quantified/mass'
    require 'quantified/length'

Add methods to Numeric (only plural, must correspond with plural unit names):

    Mass.numeric_methods :grams, :kilograms, :ounces, :pounds
    Length.numeric_methods :metres, :centimetres, :inches, :feet

Then you can do things like this:

    1.feet == 12.inches
    # => true
    
    18.inches.to_feet
    # => #<Quantified::Length: 1.5 feet>
    
    (2.5).feet.in_millimetres.to_s
    # => "762.0 millimetres"


You can easily define new attributes. Here's length.rb:

    module Quantified
      class Length < Attribute
        system :metric do
          primitive :metre
      
          one :centimetre, :is => Length.new(0.01, :metres)
          one :millimetre, :is => Length.new(0.1, :centimetres)
          one :kilometre, :is => Length.new(1000, :metres)
        end
    
        system :imperial do
          primitive :inch
          one :inch, :is => Length.new(2.540, :centimetres)
      
          one :foot, :plural => :feet, :is => Length.new(12, :inches)
          one :yard, :is => Length.new(3, :feet)
          one :mile, :is => Length.new(5280, :feet)
        end
      end
    end

Version data entries

52 entries across 52 versions & 6 rubygems

Version Path
active_shipping-0.9.5 lib/vendor/quantified/README.markdown
active_shipping-0.9.4 lib/vendor/quantified/README.markdown
active_shipping-0.9.3 lib/vendor/quantified/README.markdown
active_shipping-0.9.2 lib/vendor/quantified/README.markdown
active_shipping-0.9.1 lib/vendor/quantified/README.markdown
active_shipping-0.1.4 lib/vendor/quantified/README.markdown
active_shipping-0.1.3 lib/vendor/quantified/README.markdown
active_shipping-0.1.2 lib/vendor/quantified/README.markdown
active_shipping-0.1.1 lib/vendor/quantified/README.markdown
active_shipping-0.1.0 lib/vendor/quantified/README.markdown
active_shipping-0.0.2 lib/vendor/quantified/README.markdown
active_shipping-0.0.1 lib/vendor/quantified/README.markdown