Class: AIXM::P
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 ⇒ Object
Pressure.
-
#unit ⇒ Object
Unit.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
-
#initialize(pres, unit) ⇒ P
constructor
See the overview for examples.
- #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.
Methods included from Concerns::HashEquality
Constructor Details
Instance Attribute Details
#pres ⇒ Float #pres=(value) ⇒ Object
Pressure
34 35 36 |
# File 'lib/aixm/p.rb', line 34 def pres @pres end |
#unit ⇒ Symbol #unit=(value) ⇒ Object
Unit
42 43 44 |
# File 'lib/aixm/p.rb', line 42 def unit @unit end |
Instance Method Details
#<=>(other) ⇒ Object
86 87 88 |
# File 'lib/aixm/p.rb', line 86 def <=>(other) pres <=> other.send(:"to_#{unit}").pres end |
#==(other) ⇒ Object
91 92 93 |
# File 'lib/aixm/p.rb', line 91 def ==(other) self.class === other && (self <=> other).zero? end |
#inspect ⇒ String
50 51 52 |
# File 'lib/aixm/p.rb', line 50 def inspect %Q(#<#{self.class} #{to_s}>) end |
#to_bar ⇒ AIXM::P
Convert pressure
78 79 80 81 82 83 |
# File 'lib/aixm/p.rb', line 78 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
Convert pressure
78 79 80 81 82 83 |
# File 'lib/aixm/p.rb', line 78 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
Convert pressure
78 79 80 81 82 83 |
# File 'lib/aixm/p.rb', line 78 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
Convert pressure
78 79 80 81 82 83 |
# File 'lib/aixm/p.rb', line 78 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”).
55 56 57 |
# File 'lib/aixm/p.rb', line 55 def to_s [pres, unit].join(' '.freeze) end |
#to_torr ⇒ AIXM::P
Convert pressure
78 79 80 81 82 83 |
# File 'lib/aixm/p.rb', line 78 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
Whether pressure is zero.
26 |
# File 'lib/aixm/p.rb', line 26 def_delegator :@pres, :zero? |