Class: AIXM::P
- Inherits:
-
Object
- Object
- AIXM::P
- Extended by:
- Forwardable
- Includes:
- Comparable
- Defined in:
- lib/aixm/p.rb
Overview
pressure
Constant Summary collapse
- UNITS =
{ p: { mpa: 0.000001, psi: 0.000145037738, bar: 0.00001, torr: 0.0075006 }, mpa: { p: 1_000_000, psi: 145.037738, bar: 10, torr: 7500.6 }, psi: { p: 6894.75729, mpa: 0.00689475729, bar: 0.0689475729, torr: 51.714816529374 }, bar: { p: 100000, mpa: 0.1, psi: 14.5037738, torr: 750.06 }, torr: { p: 133.322, mpa: 0.000133322, psi: 0.019336721305636, bar: 0.00133322 } }.freeze
Instance Attribute Summary collapse
-
#pres ⇒ Float
Pressure.
-
#unit ⇒ Symbol
Unit (see UNITS).
Instance Method Summary collapse
- #<=>(other) ⇒ Integer
- #==(other) ⇒ Boolean (also: #eql?)
- #hash ⇒ Integer
-
#initialize(pres, unit) ⇒ P
constructor
A new instance of P.
- #inspect ⇒ String
-
#to_bar ⇒ AIXM::P
Convert pressure.
-
#to_mpa ⇒ AIXM::P
Convert pressure.
-
#to_p ⇒ AIXM::P
Convert pressure.
-
#to_psi ⇒ AIXM::P
Convert pressure.
-
#to_s ⇒ String
Human readable representation (e.g. “14 bar”).
-
#to_torr ⇒ AIXM::P
Convert pressure.
-
#zero? ⇒ Boolean
Whether pressure is zero.
Constructor Details
#initialize(pres, unit) ⇒ P
Returns a new instance of P.
31 32 33 |
# File 'lib/aixm/p.rb', line 31 def initialize(pres, unit) self.pres, self.unit = pres, unit end |
Instance Attribute Details
#pres ⇒ Float
Returns pressure.
26 27 28 |
# File 'lib/aixm/p.rb', line 26 def pres @pres end |
#unit ⇒ Symbol
Returns unit (see UNITS).
29 30 31 |
# File 'lib/aixm/p.rb', line 29 def unit @unit end |
Instance Method Details
#<=>(other) ⇒ Integer
71 72 73 |
# File 'lib/aixm/p.rb', line 71 def <=>(other) pres <=> other.send(:"to_#{unit}").pres end |
#==(other) ⇒ Boolean Also known as: eql?
77 78 79 |
# File 'lib/aixm/p.rb', line 77 def ==(other) self.class === other && (self <=> other).zero? end |
#hash ⇒ Integer
84 85 86 |
# File 'lib/aixm/p.rb', line 84 def hash to_s.hash end |
#inspect ⇒ String
36 37 38 |
# File 'lib/aixm/p.rb', line 36 def inspect %Q(#<#{self.class} #{to_s}>) end |
#to_bar ⇒ AIXM::P
Returns convert pressure.
62 63 64 65 66 67 |
# File 'lib/aixm/p.rb', line 62 UNITS.each_key do |target_unit| define_method "to_#{target_unit}" do return self if unit == target_unit self.class.new((pres * UNITS[unit][target_unit]).round(8), target_unit) end end |
#to_mpa ⇒ AIXM::P
Returns convert pressure.
62 63 64 65 66 67 |
# File 'lib/aixm/p.rb', line 62 UNITS.each_key do |target_unit| define_method "to_#{target_unit}" do return self if unit == target_unit self.class.new((pres * UNITS[unit][target_unit]).round(8), target_unit) end end |
#to_p ⇒ AIXM::P
Returns convert pressure.
62 63 64 65 66 67 |
# File 'lib/aixm/p.rb', line 62 UNITS.each_key do |target_unit| define_method "to_#{target_unit}" do return self if unit == target_unit self.class.new((pres * UNITS[unit][target_unit]).round(8), target_unit) end end |
#to_psi ⇒ AIXM::P
Returns convert pressure.
62 63 64 65 66 67 |
# File 'lib/aixm/p.rb', line 62 UNITS.each_key do |target_unit| define_method "to_#{target_unit}" do return self if unit == target_unit self.class.new((pres * UNITS[unit][target_unit]).round(8), target_unit) end end |
#to_s ⇒ String
Returns human readable representation (e.g. “14 bar”).
41 42 43 |
# File 'lib/aixm/p.rb', line 41 def to_s [pres, unit].join(' ') end |
#to_torr ⇒ AIXM::P
Returns convert pressure.
62 63 64 65 66 67 |
# File 'lib/aixm/p.rb', line 62 UNITS.each_key do |target_unit| define_method "to_#{target_unit}" do return self if unit == target_unit self.class.new((pres * UNITS[unit][target_unit]).round(8), target_unit) end end |
#zero? ⇒ Boolean
Returns whether pressure is zero.
23 |
# File 'lib/aixm/p.rb', line 23 def_delegator :@pres, :zero? |