aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoris2015-11-29 13:25:50 +0100
committerJoris2015-11-29 13:25:50 +0100
commitb0f00782ebc9ca6825a6c87b41e5c4888c009a65 (patch)
tree1a2b4e4288c183eb3c0a46a0837c148de6a57206
parent54d944eded3463f7d6a4dc506fc1885d0cac662d (diff)
downloadevents-b0f00782ebc9ca6825a6c87b41e5c4888c009a65.tar.gz
events-b0f00782ebc9ca6825a6c87b41e5c4888c009a65.tar.bz2
events-b0f00782ebc9ca6825a6c87b41e5c4888c009a65.zip
Authorize comments on birthdates.csv
-rw-r--r--README.md9
-rw-r--r--src/Model/BirthdateParser.hs16
2 files changed, 21 insertions, 4 deletions
diff --git a/README.md b/README.md
index 8184c16..148d4aa 100644
--- a/README.md
+++ b/README.md
@@ -10,11 +10,14 @@ Usage
Create birthdates.csv which stores birthdates:
```
-23 Oct 1982, Katie, Clarke
+# Family
30 Jan 1955, Henry, Brown
08 May 1980, Alexander, Khan
+
+# Friends
02 Aug 1976, Violet, Koval
02 Aug 1976, Jude, Martinez
+23 Oct 1982, Katie, Clarke
```
@@ -48,5 +51,5 @@ is an example notification with 3 birthdays today and 2 birthdays next week:
### Mail body
“Today, Katie Clarke is 19 years old, Henry Brown is 34 years old and Alexander
-Khan is 22 years old. Next week, Violet Koval will be 65 years old and Jude
-Martinez will be 12 years old.”
+Khan is 22 years old. Next week, Violet Koval will be 65 years old on thirsday
+and Jude Martinez will be 12 years old on friday.”
diff --git a/src/Model/BirthdateParser.hs b/src/Model/BirthdateParser.hs
index 8e8489b..9bed07a 100644
--- a/src/Model/BirthdateParser.hs
+++ b/src/Model/BirthdateParser.hs
@@ -8,8 +8,10 @@ import Control.Arrow (left)
import Data.Text (Text)
import qualified Data.Text as T
+import Data.Maybe (catMaybes)
import Text.ParserCombinators.Parsec
+import Text.Parsec.Char (endOfLine)
import Model.Birthdate
import Model.Date
@@ -32,7 +34,19 @@ validateBirthdates birthdates =
]
birthdatesParser :: Parser [Birthdate]
-birthdatesParser = many (many newline >> birthdateParser <* many newline)
+birthdatesParser = catMaybes <$> many lineParser
+
+lineParser :: Parser (Maybe Birthdate)
+lineParser =
+ (Just <$> birthdateParser <* endOfLine)
+ <|> (emptyLine >> return Nothing)
+ <|> (commentLine >> return Nothing)
+
+emptyLine :: Parser ()
+emptyLine = skipMany (char ' ') >> endOfLine >> return ()
+
+commentLine :: Parser Text
+commentLine = T.strip . T.pack <$> (spaces *> char '#' *> many (noneOf "\n") <* endOfLine)
birthdateParser :: Parser Birthdate
birthdateParser =