class NumericWithUnit::Unit::Config

Attributes

dimension[R]
si[R]
symbol[R]

Public Class Methods

new() click to toggle source
# File lib/numeric_with_unit/unit.rb, line 9
def initialize()
  @symbol = nil
  @dimension = Hash.new(0)
  @from_si = nil
  @to_si = nil
  @si = false
end

Public Instance Methods

compile() click to toggle source
# File lib/numeric_with_unit/unit.rb, line 17
def compile
  @dimension.delete_if{|k,v| v.zero?}
  
  @from_si ||= ->(x){x}
  @to_si ||= ->(x){x}

  self
end
dimension=(arg) click to toggle source
# File lib/numeric_with_unit/unit.rb, line 30
def dimension=(arg)
  raise unless arg.is_a?(Hash)
  @dimension = arg
end
from_si(&block) click to toggle source
# File lib/numeric_with_unit/unit.rb, line 40
def from_si(&block)
  if block_given?
    @from_si = block
  else
    @from_si
  end
end
from_si=(arg) click to toggle source
# File lib/numeric_with_unit/unit.rb, line 35
def from_si=(arg)
  raise unless arg.is_a?(Proc)
  @from_si = arg
end
si=(arg) click to toggle source
# File lib/numeric_with_unit/unit.rb, line 61
def si=(arg)
  raise unless [TrueClass, FalseClass].any?{|klass|arg.is_a?(klass)}
  @si = arg
end
symbol=(arg) click to toggle source
# File lib/numeric_with_unit/unit.rb, line 26
def symbol=(arg)
  @symbol = arg.to_s
end
to_si(&block) click to toggle source
# File lib/numeric_with_unit/unit.rb, line 53
def to_si(&block)
  if block_given?
    @to_si = block
  else
    @to_si
  end
end
to_si=(arg) click to toggle source
# File lib/numeric_with_unit/unit.rb, line 48
def to_si=(arg)
  raise unless arg.is_a?(Proc)
  @to_si = arg
end