Class: AIXM::P

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
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

Constructor Details

#initialize(pres, unit) ⇒ 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

#presFloat


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

def pres
  @pres
end

#unitSymbol


29
30
31
# File 'lib/aixm/p.rb', line 29

def unit
  @unit
end

Instance Method Details

#<=>(other) ⇒ Integer

See Also:

  • Object#<=>

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?

See Also:

  • Object#==

77
78
79
# File 'lib/aixm/p.rb', line 77

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

#hashInteger

See Also:

  • Object#hash

84
85
86
# File 'lib/aixm/p.rb', line 84

def hash
  to_s.hash
end

#inspectString


36
37
38
# File 'lib/aixm/p.rb', line 36

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

#to_barAIXM::P


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


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


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


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_sString


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

def to_s
  [pres, unit].join(' ')
end

#to_torrAIXM::P


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


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

def_delegator :@pres, :zero?