Module: Toodledo::CommandLine::ParserHelper
- Included in:
- AddFolderCommand, AddGoalCommand, Client
- Defined in:
- lib/toodledo/command_line/parser_helper.rb
Overview
Methods to parse a string and identify it as a Toodledo symbol.
Constant Summary collapse
- FOLDER_REGEXP =
/\*((\w+)|\[(.*?)\])/
- GOAL_REGEXP =
/\^((\w+)|\[(.*?)\])/
- CONTEXT_REGEXP =
/\@((\w+)|\[(.*?)\])/
- PRIORITY_REGEXP =
/!(top|high|medium|low|negative)/
- LEVEL_REGEXP =
Note that level must exist at the beginning of the line
/^(life|medium|short)/
- REGEXP_LIST =
Don’t include level regexp
[ FOLDER_REGEXP, GOAL_REGEXP, CONTEXT_REGEXP, PRIORITY_REGEXP ]
Instance Method Summary collapse
-
#parse_context(input) ⇒ Object
Parses a context in the format @Context or @[Spaced Context].
-
#parse_folder(input) ⇒ Object
Parses a folder in the format *Folder or *[Spaced Folder].
-
#parse_goal(input) ⇒ Object
Parses a goal in the format ^Goal or ^[Spaced Goal].
- #parse_level(input) ⇒ Object
-
#parse_priority(input) ⇒ Object
Parses priority in the format !priority (top, high, medium, low, negative).
-
#parse_remainder(line) ⇒ Object
Returns the bit after we’ve looked for *Folder, @Context & ^Goal.
-
#strip_brackets(inword) ⇒ Object
Strips a string of [ and ] characters.
Instance Method Details
#parse_context(input) ⇒ Object
Parses a context in the format @Context or @[Spaced Context]
32 33 34 35 36 |
# File 'lib/toodledo/command_line/parser_helper.rb', line 32 def parse_context(input) match_data = CONTEXT_REGEXP.match(input) return nil if (match_data == nil) return strip_brackets(match_data[1]) end |
#parse_folder(input) ⇒ Object
Parses a folder in the format *Folder or *[Spaced Folder]
39 40 41 42 43 |
# File 'lib/toodledo/command_line/parser_helper.rb', line 39 def parse_folder(input) match_data = FOLDER_REGEXP.match(input) return match_data if (match_data == nil) return strip_brackets(match_data[1]) end |
#parse_goal(input) ⇒ Object
Parses a goal in the format ^Goal or ^[Spaced Goal]
46 47 48 49 50 |
# File 'lib/toodledo/command_line/parser_helper.rb', line 46 def parse_goal(input) match_data = GOAL_REGEXP.match(input) return match_data if (match_data == nil) return strip_brackets(match_data[1]) end |
#parse_level(input) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/toodledo/command_line/parser_helper.rb', line 77 def parse_level(input) match_data = LEVEL_REGEXP.match(input) if (match_data == nil) return nil end p = match_data[1] case p when 'life' return Toodledo::Goal::LIFE_LEVEL when 'medium' return Toodledo::Goal::MEDIUM_LEVEL when 'short' return Toodledo::Goal::SHORT_LEVEL else return nil end end |
#parse_priority(input) ⇒ Object
Parses priority in the format !priority (top, high, medium, low, negative)
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/toodledo/command_line/parser_helper.rb', line 54 def parse_priority(input) match_data = PRIORITY_REGEXP.match(input) if (match_data == nil) return nil end p = match_data[1] case p when 'top' return Toodledo::Priority::TOP when 'high' return Toodledo::Priority::HIGH when 'medium' return Toodledo::Priority::MEDIUM when 'low' return Toodledo::Priority::LOW when 'negative' return Toodledo::Priority::NEGATIVE else return nil end end |
#parse_remainder(line) ⇒ Object
Returns the bit after we’ve looked for *Folder, @Context & ^Goal
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/toodledo/command_line/parser_helper.rb', line 97 def parse_remainder(line) input = line # Strip out anything that isn't folder, goal or context. for regexp in REGEXP_LIST input = input.sub(regexp, '') end input.strip! return input end |
#strip_brackets(inword) ⇒ Object
Strips a string of [ and ] characters
111 112 113 |
# File 'lib/toodledo/command_line/parser_helper.rb', line 111 def strip_brackets(inword) return inword.gsub(/\[|\]/, '') end |