summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Crute <mcrute@gmail.com>2010-02-04 21:54:38 -0500
committerMike Crute <mcrute@gmail.com>2010-02-04 21:54:38 -0500
commit5f6c2c4c3f9aeddd5e07e0d2bb25df15b2cc0eb0 (patch)
treec9e28d004dc87b9f0a986333035662b55afabf7a
parentc4fd2cc59dad0d4ca91a881b48bd064cc9c395f9 (diff)
downloadkronos-5f6c2c4c3f9aeddd5e07e0d2bb25df15b2cc0eb0.tar.bz2
kronos-5f6c2c4c3f9aeddd5e07e0d2bb25df15b2cc0eb0.tar.xz
kronos-5f6c2c4c3f9aeddd5e07e0d2bb25df15b2cc0eb0.zip
Implementing tag parsing
-rw-r--r--kronos/parser.py19
-rw-r--r--kronos/tests/test_parser.py5
2 files changed, 21 insertions, 3 deletions
diff --git a/kronos/parser.py b/kronos/parser.py
index b18b4f9..8d93391 100644
--- a/kronos/parser.py
+++ b/kronos/parser.py
@@ -13,19 +13,34 @@ class Activity(object):
13 self.activity = activity 13 self.activity = activity
14 self.description = description 14 self.description = description
15 self.category = category 15 self.category = category
16 self.tags = []
16 17
17 18
18def parse_activity(text): 19def parse_activity(text):
19 description = None 20 description = None
21 tags = []
20 if ',' in text: 22 if ',' in text:
21 text, description = text.split(',', 1) 23 text, description = text.split(',', 1)
22 description = description.strip() 24 description = description.strip()
23 25
26 tokens = description.split(' ')
27 tags = parse_tags(tokens)
28 description = strip_tags(tokens)
29
24 category = None 30 category = None
25 if '@' in text: 31 if '@' in text:
26 text, category = text.split('@', 1) 32 text, category = text.split('@', 1)
27 category = category.strip() 33 category = category.strip()
28 34
29 activity = text.strip() 35 activity = Activity(text.strip(), description, category)
36 activity.tags = tags
37
38 return activity
39
40
41def parse_tags(tokens):
42 return [token.lstrip('#') for token in tokens if token.startswith('#')]
43
30 44
31 return Activity(activity, description, category) 45def strip_tags(tokens):
46 return ' '.join([token for token in tokens if not token.startswith('#')])
diff --git a/kronos/tests/test_parser.py b/kronos/tests/test_parser.py
index 1f9ec40..015ae06 100644
--- a/kronos/tests/test_parser.py
+++ b/kronos/tests/test_parser.py
@@ -55,7 +55,10 @@ class TestWhenParsingWithTags(object):
55 self.results = parse_activity(test_input) 55 self.results = parse_activity(test_input)
56 56
57 def test_should_get_tags(self): 57 def test_should_get_tags(self):
58 pass 58 assert_equals(self.results.tags, ['tag1', 'tag2'])
59
60 def test_should_not_include_tags_in_description(self):
61 assert_equals(self.results.description, "Some cool stuff!")
59 62
60 63
61class TestWhenParsingWithTimeOffset(object): 64class TestWhenParsingWithTimeOffset(object):