Class: Numeric

Inherits:
Object show all
Includes:
Units
Defined in:
lib/units/base.rb,
lib/units/standard.rb,
lib/ruby_extensions.rb,
lib/sequel/lib/sequel/extensions/blank.rb,
lib/sequel/lib/sequel/extensions/sql_expr.rb

Constant Summary collapse

WEIGHT =
{
  :pounds             =>  1.0,
  :ounces             =>  0.0625,
  :kilograms          =>  0.45359237,
  :grams              =>  453.59237
}
WEIGHT_ALIASES =
{             
  :pounds             =>  [ :lb, :lbs, :pound       ],
  :ounces             =>  [ :oz, :ozs, :ounce       ],
  :kilograms          =>  [ :kg, :kgs, :kilogram    ],
  :grams              =>  [ :gm, :gms, :gram        ]
}
VOLUME =
{
  :pints              =>  0.125, 
  :milliliters        =>  0.000264172051, 
  :cubic_feet         =>  7.48051945, 
  :cups               =>  0.0625, 
  :microliters        =>  2.64172051, 
  :cubic_inches       =>  0.00432900431, 
  :liters             =>  0.264172051, 
  :cubic_centimeters  =>  0.000264172051, 
  :cubic_yards        =>  201.974025, 
  :hectoliters        =>  26.4172051, 
  :fluid_ounces       =>  0.0078125, 
  :cubic_millimeters  =>  2.64172051, 
  :gallons            =>  1, 
  :deciliters         =>  0.0264172051, 
  :tablespoons        =>  0.00390625, 
  :cubic_meters       =>  264.172051, 
  :quarts             =>  0.25, 
  :centiliters        =>  0.00264172051, 
  :teaspoons          =>  0.00130208333, 
  :cubic_decimeters   =>  0.264172051
}
VOLUME_ALIASES =
{
  :liters             => [ :liter, :l              ],
  :hectoliters        => [ :hectoliter, :hl        ],
  :deciliters         => [ :deciliter, :dl         ],
  :centiliters        => [ :centiliter, :cl        ],
  :milliliters        => [ :milliliter, :ml        ],
  :microliters        => [ :microliter, :ul        ],
  :cubic_centimeters  => [ :cubic_centimeter, :cm3 ],
  :cubic_millimeters  => [ :cubic_millimeter, :mm3 ],
  :cubic_meters       => [ :cubic_meter, :m3       ],
  :cubic_decimeters   => [ :cubic_decimeter, :dm3  ],
  :cubic_feet         => [ :cubic_foot, :f3        ],
  :cubic_inches       => [ :cubic_inch, :i3        ],
  :cubic_yards        => [ :cubic_yard, :y3        ],
  :gallons            => [ :gallon, :gal, :gals    ],
  :quarts             => [ :quart, :qt, :qts       ],
  :pints              => [ :pint, :pt, :pts        ],
  :cups               => [ :cup                    ],
  :gills              => [ :gill                   ],
  :fluid_ounces       => [ :fluid_oz, :fluid_ozs   ],
  :tablespoons        => [ :tablespoon, :tbsp      ],
  :teaspoons          => [ :teaspoon, :tsp         ],
  :fluid_drams        => [ :fluid_dram             ],
  :minims             => [ :minim                  ]
}
TIME =
{                     
  :seconds            =>  1.0,
  :minutes            =>  60.0,
  :hours              =>  3600.0,
  :days               =>  86400.0,
  :weeks              =>  604800.0,
  :years              =>  31449600.0
}
TIME_ALIASES =
{             
  :seconds            =>  [ :sec, :second         ],
  :minutes            =>  [ :min, :mins, :minute  ],
  :hours              =>  [ :hour                 ],
  :days               =>  [ :day                  ],
  :weeks              =>  [ :week                 ],
  :years              =>  [ :year                 ]
}
SIZE =
{
  :bytes              =>  1.0,
  :bits               =>  8.0,
  :kilobytes          =>  1024.0,
  :megabytes          =>  1048576.0,
  :gigabytes          =>  1073741824.0,
  :terabytes          =>  1099511627776.0,
  :petabytes          =>  1.12589991e15
}
SIZE_ALIASES =
{               
  :bits               =>  [ :bit                  ],
  :bytes              =>  [ :b, :byte             ],
  :kilobytes          =>  [ :kb, :kilobyte        ],
  :megabytes          =>  [ :mb, :megabyte        ],
  :gigabytes          =>  [ :gb, :gigabyte        ],
  :terabytes          =>  [ :tb, :terabyte        ],
  :petabytes          =>  [ :pb, :petabyte        ]
}
LENGTH =
{                     
  :inches             =>  1.0,
  :feet               =>  12.0,
  :meters             =>  39.3700787,
  :kilometers         =>  39370.0787,
  :milimeters         =>  0.0393700787,
  :centimeters        =>  0.393700787,
  :miles              =>  63360.0
}
LENGTH_ALIASES =
{
  :inches             =>  [ :inch                 ],
  :feet               =>  [ :foot                 ],
  :miles              =>  [ :mile                 ],
  :meters             =>  [ :m, :meter            ],
  :kilometers         =>  [ :km, :kilometer       ],
  :milimeters         =>  [ :mm, :milimeter       ],
  :centimeters        =>  [ :cm, :centimeter      ]
}

Instance Attribute Summary

Attributes included from Units

#kind, #unit

Instance Method Summary collapse

Methods included from Units

#method_missing

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Units

Instance Method Details

#blank?Boolean

Numerics are never blank (not even 0)


26
27
28
# File 'lib/sequel/lib/sequel/extensions/blank.rb', line 26

def blank?
  false
end

#sql_exprObject

Returns a copy of the object wrapped in a Sequel::SQL::NumericExpression, allowing easy use of Sequel's DSL:

1.sql_expr < :a  # 1 < a

74
75
76
# File 'lib/sequel/lib/sequel/extensions/sql_expr.rb', line 74

def sql_expr
  Sequel::SQL::NumericExpression.new(:NOOP, self)
end

#to_minutes_seconds_stringObject


32
33
34
# File 'lib/ruby_extensions.rb', line 32

def to_minutes_seconds_string
  [self/60 % 60, self % 60].map{|t| t.to_s.rjust(2,'0')}.join(':')
end