Class: AIXM::P

Inherits:
Object show all
Extended by:
Forwardable
Includes:
Concerns::HashEquality, Comparable
Defined in:
lib/aixm/p.rb

Overview

Pressure

Examples:

AIXM.d(14, :bar)

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

Instance Method Summary collapse

Methods included from Concerns::HashEquality

#eql?, #hash

Constructor Details

#initialize(pres, unit) ⇒ P

See the overview for examples.


45
46
47
# File 'lib/aixm/p.rb', line 45

def initialize(pres, unit)
  self.pres, self.unit = pres, unit
end

Instance Attribute Details

#presFloat #pres=(value) ⇒ Object

Pressure

Overloads:

  • #presFloat

    Returns:

    • (Float)
  • #pres=(value) ⇒ Object

    Parameters:

    • value (Float)

34
35
36
# File 'lib/aixm/p.rb', line 34

def pres
  @pres
end

#unitSymbol #unit=(value) ⇒ Object

Unit

Overloads:

  • #unitSymbol

    Returns any of UNITS.

    Returns:

    • (Symbol)

      any of UNITS

  • #unit=(value) ⇒ Object

    Parameters:

    • value (Symbol)

      any of UNITS


42
43
44
# File 'lib/aixm/p.rb', line 42

def unit
  @unit
end

Instance Method Details

#<=>(other) ⇒ Object

See Also:

  • Object#<=>

86
87
88
# File 'lib/aixm/p.rb', line 86

def <=>(other)
  pres <=> other.send(:"to_#{unit}").pres
end

#==(other) ⇒ Object

See Also:

  • Object#==

91
92
93
# File 'lib/aixm/p.rb', line 91

def ==(other)
  self.class === other  && (self <=> other).zero?
end

#inspectString

Returns:

  • (String)

50
51
52
# File 'lib/aixm/p.rb', line 50

def inspect
  %Q(#<#{self.class} #{to_s}>)
end

#to_barAIXM::P

Convert pressure

Returns:


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_mpaAIXM::P

Convert pressure

Returns:


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_pAIXM::P

Convert pressure

Returns:


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_psiAIXM::P

Convert pressure

Returns:


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_sString

Returns human readable representation (e.g. “14 bar”).

Returns:

  • (String)

    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_torrAIXM::P

Convert pressure

Returns:


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.

Returns:

  • (Boolean)

26
# File 'lib/aixm/p.rb', line 26

def_delegator :@pres, :zero?