Class: Unite::Quantity

Inherits:
Object
  • Object
show all
Includes:
Arithmetic, Conversion, Dimension::Vector, Simplify
Defined in:
lib/unite/quantity.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Simplify

#simplify

Methods included from Arithmetic

#*, #+, #-, #/, #coerce

Methods included from Conversion

#convert_to, #convert_to!

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 = {}) ⇒ Quantity

Returns a new instance of Quantity.



10
11
12
13
14
15
# File 'lib/unite/quantity.rb', line 10

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.



24
25
26
# File 'lib/unite/quantity.rb', line 24

def cached_expression
  @cached_expression
end

#denominatorObject

Returns the value of attribute denominator.



24
25
26
# File 'lib/unite/quantity.rb', line 24

def denominator
  @denominator
end

#nameObject

Returns the value of attribute name.



24
25
26
# File 'lib/unite/quantity.rb', line 24

def name
  @name
end

#numeratorObject

Returns the value of attribute numerator.



24
25
26
# File 'lib/unite/quantity.rb', line 24

def numerator
  @numerator
end

#valueObject

Returns the value of attribute value.



24
25
26
# File 'lib/unite/quantity.rb', line 24

def value
  @value
end

Class Method Details

.init(value, unit = "") ⇒ Object

Initialize the quantity,

A nil value is treated as 0.0



20
21
22
# File 'lib/unite/quantity.rb', line 20

def self.init value, unit = ""
  new :expression => [value || 0.0, unit].reject(&:blank?).join('*')
end