Class: NumericWithUnit::Unit::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/numeric_with_unit/unit.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



9
10
11
12
13
14
15
# 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

Instance Attribute Details

#dimensionObject

Returns the value of attribute dimension.



6
7
8
# File 'lib/numeric_with_unit/unit.rb', line 6

def dimension
  @dimension
end

#siObject

Returns the value of attribute si.



7
8
9
# File 'lib/numeric_with_unit/unit.rb', line 7

def si
  @si
end

#symbolObject

Returns the value of attribute symbol.



6
7
8
# File 'lib/numeric_with_unit/unit.rb', line 6

def symbol
  @symbol
end

Instance Method Details

#compileObject



17
18
19
20
21
22
23
24
# 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

#from_si(&block) ⇒ Object



40
41
42
43
44
45
46
# 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) ⇒ Object



35
36
37
38
# File 'lib/numeric_with_unit/unit.rb', line 35

def from_si=(arg)
  raise unless arg.is_a?(Proc)
  @from_si = arg
end

#to_si(&block) ⇒ Object



53
54
55
56
57
58
59
# 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) ⇒ Object



48
49
50
51
# File 'lib/numeric_with_unit/unit.rb', line 48

def to_si=(arg)
  raise unless arg.is_a?(Proc)
  @to_si = arg
end