Repository: pylover/sunrise

Issue:
Add subtraction styles to calculator class.

Discussion:

Patch:
diff --git a/sunrise/actions.py b/sunrise/actions.py
index f70b909..44ca2dd 100644
--- a/sunrise/actions.py
+++ b/sunrise/actions.py
@@ -16,6 +16,7 @@ class Calculator(Action):
         self.operator = {
             'Add': '+',
             'Sub': '-',
+            'subtract': '-',
         }[operator] if operator not in self.operators else operator
         self.numbers = [a, b]
 
@@ -30,7 +31,13 @@ patterns = [
     ),
     (
         re.compile(
-            r'(?P<operator>Add|Sub)\s*(?P<a>\d+)\s*(with|by)\s*(?P<b>\d+)'
+            r'(?P<operator>Add)\s*(?P<a>\d+)\s*(with|by)\s*(?P<b>\d+)'
+        ),
+        Calculator
+    ),
+    (
+        re.compile(
+            r'(?P<operator>Sub|subtract)\s*(?P<b>\d+)\s*(from)\s*(?P<a>\d+)'
         ),
         Calculator
     ),


Test patch:
diff --git a/tests/test_calculator.py b/tests/test_calculator.py
index 7c837ea..36be715 100644
--- a/tests/test_calculator.py
+++ b/tests/test_calculator.py
@@ -4,5 +4,7 @@ from sunrise import do
 def test_parser():
     assert '6' == do('2 + 4')
     assert '6' == do('Add 2 by 4')
+    assert '2' == do('subtract 2 from 4')
+    assert '2' == do('4 - 2')