aboutsummaryrefslogtreecommitdiffstats
path: root/parser.go
diff options
context:
space:
mode:
authorGrant Ammons <gammons@gmail.com>2016-04-24 10:22:33 -0400
committerGrant Ammons <gammons@gmail.com>2016-04-24 10:22:33 -0400
commit63893587cb41a1980318b60bf05fafbf433a24ab (patch)
tree39c93f3a1735ef33d028ab9ef44fc0ac15049208 /parser.go
parent6bb90375f4efb2f390a61ede0df70eea1ef1f50f (diff)
Organize things a bit better
Diffstat (limited to 'parser.go')
-rw-r--r--parser.go87
1 files changed, 0 insertions, 87 deletions
diff --git a/parser.go b/parser.go
deleted file mode 100644
index d3b5968..0000000
--- a/parser.go
+++ /dev/null
@@ -1,87 +0,0 @@
-package todolist
-
-import (
- "fmt"
- "regexp"
- "strings"
- "time"
-
- "github.com/jinzhu/now"
-)
-
-type Parser struct{}
-
-func (p *Parser) Parse(input string) *Todo {
- todo := NewTodo()
- todo.Subject = p.Subject(input)
- todo.Projects = p.Projects(input)
- todo.Contexts = p.Contexts(input)
- if p.hasDue(input) {
- todo.FormattedDue = p.Due(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, _ := regexp.Compile(`\+\w+`)
- return p.matchWords(input, r)
-}
-
-func (p *Parser) Contexts(input string) []string {
- r, err := regexp.Compile(`\@\w+`)
- if err != nil {
- fmt.Println("regex error", err)
- }
- return p.matchWords(input, r)
-}
-
-func (p *Parser) hasDue(input string) bool {
- r, _ := regexp.Compile(`due \w+$`)
- return r.MatchString(input)
-}
-
-func (p *Parser) Due(input string) time.Time {
- r, _ := regexp.Compile(`due .*$`)
-
- res := r.FindString(input)
- res = res[4:len(res)]
- switch {
- case res == "today":
- return now.BeginningOfDay()
- case res == "tomorrow" || res == "tom":
- return now.BeginningOfDay().AddDate(0, 0, 1)
- case res == "monday" || res == "mon":
- n := now.BeginningOfDay()
- return now.New(n).Monday().AddDate(0, 0, 7)
- case res == "tuesday" || res == "tue":
- n := now.BeginningOfDay()
- return now.New(n).Monday().AddDate(0, 0, 1)
- case res == "wednesday" || res == "wed":
- n := now.BeginningOfDay()
- return now.New(n).Monday().AddDate(0, 0, 2)
- case res == "next week":
- n := now.BeginningOfDay()
- return now.New(n).Monday().AddDate(0, 0, 7)
- }
- //return now.Parse(input)
- return time.Now()
-}
-
-func (p *Parser) matchWords(input string, r *regexp.Regexp) []string {
- results := r.FindAllString(input, -1)
- ret := []string{}
-
- for _, val := range results {
- ret = append(ret, val[1:len(val)])
- }
- return ret
-}