class Scalar::SupportClasses::ConversionTable
Attributes
base_unit[RW]
table[RW]
Public Class Methods
new(base_unit:)
click to toggle source
# File lib/scalar/support_classes/conversion_table.rb, line 4 def initialize(base_unit:) self.table = {} self.base_unit = base_unit add(name: base_unit, base_unit_per: 1.to_r) end
Public Instance Methods
add(name:, base_unit_per:)
click to toggle source
# File lib/scalar/support_classes/conversion_table.rb, line 10 def add(name:, base_unit_per:) raise unless name.is_a? Symbol table[name] = {name => 1.to_r} table.keys.each do |k| table[k][name] = (table[k][base_unit] / base_unit_per).to_r table[name][k] = 1.to_r / table[k][name] end end
call(from:, to:)
click to toggle source
# File lib/scalar/support_classes/conversion_table.rb, line 21 def call(from:, to:) table[from][to] end