aboutsummaryrefslogtreecommitdiffstats
path: root/parser.go
diff options
context:
space:
mode:
authorGrant Ammons <gammons@gmail.com>2016-04-23 16:59:52 -0400
committerGrant Ammons <gammons@gmail.com>2016-04-23 16:59:52 -0400
commit8138ffaf380fb646b6877dd20f874735eddd2d6d (patch)
treeda3077b68ff432d4ffe2aeae234ecb70843a3165 /parser.go
Initial commit
Diffstat (limited to 'parser.go')
-rw-r--r--parser.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/parser.go b/parser.go
new file mode 100644
index 0000000..bb54b97
--- /dev/null
+++ b/parser.go
@@ -0,0 +1,40 @@
+package todolist
+
+import (
+ "fmt"
+ "regexp"
+ "strings"
+)
+
+type Parser struct{}
+
+func (p *Parser) Parse(input string) *Todo {
+ todo := NewTodo()
+ todo.Subject = p.Subject(input)
+ todo.Projects = p.Projects(input)
+ return todo
+}
+
+func (p *Parser) Subject(input string) string {
+ if strings.Contains(input, " due") {
+ index := strings.LastIndex(input, " due")
+ return input[0:index]
+ } else {
+ return input
+ }
+}
+
+func (p *Parser) Projects(input string) []string {
+ r, err := regexp.Compile(`\+\w+`)
+ if err != nil {
+ fmt.Printf("There was a problem with the regexp", err)
+ }
+ results := r.FindAllString(input, -1)
+ ret := []string{}
+
+ for _, val := range results {
+ fmt.Println("Result is ", val)
+ ret = append(ret, val[1:len(val)])
+ }
+ return ret
+}