Class: Unite::Unit

Inherits:
Object
  • Object
show all
Includes:
Comparison, Dimension::Vector, SiFactor
Defined in:
lib/unite/unit.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Fraction

#expanded_denominator, #expanded_numerator, #expression, #expression=, #inverse, #reduce, #unit

Methods included from Comparison

#==, #compatible!, #compatible?, #compatible_units

Methods included from Dimension::Integer

#dimension_int, #property, #property_name

Methods included from Dimension::Vector

#dimension_vector

Constructor Details

#initialize(attributes = {}) ⇒ Unit

Returns a new instance of Unit.



9
10
11
12
13
14
# File 'lib/unite/unit.rb', line 9

def initialize(attributes = {})
  attributes.each do |name, value|
    send("#{name}=", value)
  end
  super
end

Instance Attribute Details

#cached_expressionObject

Returns the value of attribute cached_expression.



23
24
25
# File 'lib/unite/unit.rb', line 23

def cached_expression
  @cached_expression
end

#denominatorObject

Returns the value of attribute denominator.



23
24
25
# File 'lib/unite/unit.rb', line 23

def denominator
  @denominator
end

#nameObject

Returns the value of attribute name.



23
24
25
# File 'lib/unite/unit.rb', line 23

def name
  @name
end

#numeratorObject

Returns the value of attribute numerator.



23
24
25
# File 'lib/unite/unit.rb', line 23

def numerator
  @numerator
end

Class Method Details

.init(unit) ⇒ Object

Initialize the quantity,

A nil value is treated as 0.0



19
20
21
# File 'lib/unite/unit.rb', line 19

def self.init unit
  new :expression => "#{unit}"
end

Instance Method Details

#valueObject



26
27
28
# File 'lib/unite/unit.rb', line 26

def value
  @value ||= BigDecimal.new(1)
end

#value=(x) ⇒ Object



30
31
32
# File 'lib/unite/unit.rb', line 30

def value= x
  value
end