Module firkin :: Class Unitmanager
[hide private]
[frames] | no frames]

Class Unitmanager

source code

object --+
         |
        Unitmanager

Manages units and ways to convert them

Instance Methods [hide private]
 
__contains__(self, item)
item in self
source code
 
__getitem__(self, index)
self[index]
source code
 
__init__(self)
Constructor
source code
 
add(self, unit, other=None, factor=1.0, offset=0.0)
Adds unit unit.
source code
 
convert(self, amount, unit, dest)
Convert amount unit to the units in dest that has the shortest conversion path
source code
 
get_conversion(self, unit, dest)
Gets the shortest conversion path from unit to one of the units in dest
source code
 
shortest_path(self, start, end, path=None)
Finds the shortest conversion path between start and end.
source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__contains__(self, item)
(In operator)

source code 

item in self

True if item is a unit addeed by add

__getitem__(self, index)
(Indexing operator)

source code 

self[index]

List of Entry objects for unit index

__init__(self)
(Constructor)

source code 

Constructor

Overrides: object.__init__

add(self, unit, other=None, factor=1.0, offset=0.0)

source code 

Adds unit unit. If other is not None it adds a conversion rule unit=factor*other+offset

Raises:
  • ValueError - if other is not None and not a known unit

convert(self, amount, unit, dest)

source code 

Convert amount unit to the units in dest that has the shortest conversion path

Returns:
tuple (new amount, new unit)

get_conversion(self, unit, dest)

source code 

Gets the shortest conversion path from unit to one of the units in dest

Parameters:
  • unit (unit that has been added with add) - unit to start with
  • dest (list of units which have been added with add. Can be a single unit too.) - list of units

shortest_path(self, start, end, path=None)

source code 

Finds the shortest conversion path between start and end.

Parameters:
  • start (a unit that has been added by add) - unit to start with
  • end (a unit that has been added by add) - unit to end with