From 0c442a571d4e297f476ab0ae2968a11562db20df Mon Sep 17 00:00:00 2001
From: Piotr Maslanka <piotr.maslanka@henrietta.com.pl>
Date: Sat, 9 Dec 2017 08:56:29 +0100
Subject: [PATCH] refactor

---
 README.md                                       |  4 +---
 firanka/ranges.py                               | 13 +++++++++++++
 firanka/series/__init__.py                      |  2 +-
 firanka/series/{linear.py => interpolations.py} |  0
 tests/test_range.py                             |  2 +-
 5 files changed, 16 insertions(+), 5 deletions(-)
 rename firanka/series/{linear.py => interpolations.py} (100%)

diff --git a/README.md b/README.md
index 97a694c..f982022 100644
--- a/README.md
+++ b/README.md
@@ -119,9 +119,7 @@ You can create Ranges as follows:
 Range(-5, 5, True, False) == Range('<-5;5)')
 ```
 
-First boolean argument signifies whether the interval is left-closed,
-and second whether it is right-closed.
-
+For more information [use the source](firanka/ranges.py#L33)
 Range's are immutable and hashable. They can be sliced:
 
 ```python
diff --git a/firanka/ranges.py b/firanka/ranges.py
index a2b2ae1..b0b57fb 100644
--- a/firanka/ranges.py
+++ b/firanka/ranges.py
@@ -31,6 +31,16 @@ class Range(object):
                      self.right_inc)
 
     def __init__(self, *args):
+        """
+        Create like:
+
+        * Range('<a;b>')
+        * Range(a, b, is_left_closed_, is_right_closed)
+        * Range(a, b) - will have both sides closed, unless one is inf
+        * Range(slice(a, b)) - will have both sides closed, unless one is None
+
+        :param args:
+        """
         if len(args) == 1:
             rs, = args
             if isinstance(rs, type(self)):
@@ -48,6 +58,9 @@ class Range(object):
                 start, stop = rs[1:-1].split(';')
                 args = float(start), float(stop), rs[0] == '<', rs[-1] == '>'
 
+        elif len(args) == 2:
+            args = args[0], args[1], not math.isinf(args[0]), not math.isinf(args[1])
+
         q = lambda a, b, args: args[a] and math.isinf(args[b])
 
         if q(2, 0, args) or q(3, 1, args):
diff --git a/firanka/series/__init__.py b/firanka/series/__init__.py
index 0a890c4..59a5abc 100644
--- a/firanka/series/__init__.py
+++ b/firanka/series/__init__.py
@@ -1,7 +1,7 @@
 # coding=UTF-8
 from __future__ import absolute_import
 from .base import FunctionSeries, DiscreteSeries, Series
-from .linear import LinearInterpolationSeries, SCALAR_LINEAR_INTERPOLATOR
+from .interpolations import LinearInterpolationSeries, SCALAR_LINEAR_INTERPOLATOR
 from .modulo import ModuloSeries
 
 __all__ = [
diff --git a/firanka/series/linear.py b/firanka/series/interpolations.py
similarity index 100%
rename from firanka/series/linear.py
rename to firanka/series/interpolations.py
diff --git a/tests/test_range.py b/tests/test_range.py
index 5463f90..f95cb6f 100644
--- a/tests/test_range.py
+++ b/tests/test_range.py
@@ -38,7 +38,7 @@ class TestRange(unittest.TestCase):
     def test_str_and_repr_and_bool(self):
         p = Range(-1, 1, True, True)
         self.assertEqual(eval(repr(p)), p)
-        self.assertEqual(str(Range(-1, 1, True, True)), '<-1;1>')
+        self.assertEqual(str(Range(-1, 1)), '<-1;1>')
 
     def test_constructor(self):
         self.assertRaises(ValueError, lambda: Range('#2;3>'))
-- 
GitLab