Skip to content

Commit

Permalink
Add unit conversions for inches.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken Kundert authored and Ken Kundert committed Jan 9, 2018
1 parent ca22bf3 commit 64a2ac4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
11 changes: 9 additions & 2 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@

# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.todo', 'sphinx.ext.coverage', 'sphinx.ext.viewcode']
extensions = '''
sphinx.ext.autodoc
sphinx.ext.coverage
sphinx.ext.doctest
sphinx.ext.napoleon
sphinx.ext.todo
sphinx.ext.viewcode
'''.split()

# Add any paths that contain templates here, relative to this directory.
templates_path = ['.templates']
Expand All @@ -41,7 +48,7 @@

# General information about the project.
project = u'quantiphy'
copyright = u'2017, Ken Kundert'
copyright = u'2017-2018, Ken Kundert'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down
9 changes: 5 additions & 4 deletions doc/user.rst
Original file line number Diff line number Diff line change
Expand Up @@ -371,14 +371,15 @@ To do this conversion, *QuantiPhy* examines the given units (°F) and the desire
units (K) and chooses the appropriate converter. *QuantiPhy* provides
a collection of pre-defined converters for common units:

====== ===============================================================
====== ================================================================
K: K, F, °F, R, °R
C, °C: K, C, °C, F, °F, R, °R
m: km, m, cm, mm, um, μm, micron, nm, Å, angstrom, mi, mile, miles
m: km, m, cm, mm, um, μm, micron, nm, Å, angstrom, mi, mile, miles,
in, inch, inches
g: oz, lb, lbs
s: s, sec, min, hour, hr , day
s: s, sec, min, hour, hr, day
b: B
====== ===============================================================
====== ================================================================

You can also create your own converters using :class:`quantiphy.UnitConversion`:

Expand Down
1 change: 1 addition & 0 deletions quantiphy.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ def __str__(self):
UnitConversion('m', 'nm', 1/1000000000)
UnitConversion('m', 'Å angstrom', 1/10000000000)
UnitConversion('m', 'mi mile miles', 1609.344)
UnitConversion('m', 'in inch inches', 0.0254)

# Mass conversions {{{2
UnitConversion('g', 'lb lbs', 453.59237)
Expand Down
3 changes: 3 additions & 0 deletions test_unit_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ def test_distance():
assert q.render(scale='mi') == '621.37 umi'
assert q.render(scale='mile') == '621.37 umile'
assert q.render(scale='miles') == '621.37 umiles'
assert q.render(scale='in') == '39.37 in'
assert q.render(scale='inch') == '39.37 inch'
assert q.render(scale='inches') == '39.37 inches'

q=Quantity('1_m')
assert q.render() == '1 m'
Expand Down

0 comments on commit 64a2ac4

Please sign in to comment.