Class: ConvertUnit::HighPressure

Inherits:
Base
  • Object
show all
Extended by:
PreProcess::HighPressure
Defined in:
lib/convert_unit/high_pressure.rb

Constant Summary collapse

UNITS_SYMBOL =
load_units_symbol
UNITS =
load_available_units
CONVERSION_RATE =
load_conversion_rate

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PreProcess::HighPressure

file_path

Methods included from PreProcess

#file_path, #load_available_units, #load_conversion_rate, #load_units_symbol

Methods inherited from Base

#+, #-, #==, #===, #inspect, #to_c, #to_f, #to_i, #to_r, #to_s

Constructor Details

#initialize(value, unit) ⇒ HighPressure

Returns a new instance of HighPressure.



13
14
15
16
17
# File 'lib/convert_unit/high_pressure.rb', line 13

def initialize(value, unit)
  unit_symbol = HighPressure::UNITS_SYMBOL[unit] || unit
  @conversion_rate_for_one_unit = HighPressure::CONVERSION_RATE
  super(value, unit_symbol, HighPressure::UNITS)
end

Instance Attribute Details

#unitObject

Returns the value of attribute unit.



11
12
13
# File 'lib/convert_unit/high_pressure.rb', line 11

def unit
  @unit
end

#valueObject

Returns the value of attribute value.



11
12
13
# File 'lib/convert_unit/high_pressure.rb', line 11

def value
  @value
end

Instance Method Details

#to(c_unit) ⇒ Object

Raises:

  • (ArgumentError)


19
20
21
22
23
24
# File 'lib/convert_unit/high_pressure.rb', line 19

def to(c_unit)
  c_unit.downcase!
  unit_symbol = HighPressure::UNITS_SYMBOL[c_unit] || c_unit
  raise ArgumentError, 'Impossible conversion type' unless HighPressure::UNITS.include?(unit_symbol)
  HighPressure.new(convert_to(unit_symbol), unit_symbol)
end