Class: Todoist::DateParser
- Inherits:
-
Object
- Object
- Todoist::DateParser
- Defined in:
- lib/todoist/date_parser.rb
Instance Attribute Summary collapse
-
#dates ⇒ Object
readonly
Returns the value of attribute dates.
-
#due_parts ⇒ Object
readonly
Returns the value of attribute due_parts.
Instance Method Summary collapse
- #due_regex ⇒ Object
-
#initialize(due_str) ⇒ DateParser
constructor
A new instance of DateParser.
- #parse ⇒ Object
Constructor Details
#initialize(due_str) ⇒ DateParser
Returns a new instance of DateParser.
5 6 7 8 9 10 |
# File 'lib/todoist/date_parser.rb', line 5 def initialize(due_str) due_str.downcase! @due_parts = due_str.match(due_regex) return if @due_parts.nil? @dates = @due_parts[:dates].split(",").map(&:strip) end |
Instance Attribute Details
#dates ⇒ Object (readonly)
Returns the value of attribute dates.
3 4 5 |
# File 'lib/todoist/date_parser.rb', line 3 def dates @dates end |
#due_parts ⇒ Object (readonly)
Returns the value of attribute due_parts.
3 4 5 |
# File 'lib/todoist/date_parser.rb', line 3 def due_parts @due_parts end |
Instance Method Details
#due_regex ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/todoist/date_parser.rb', line 15 def due_regex %r{^(?:ev(?:ery)? # string must start with ev or every (?<bang>!)?) # optional bang \s+(?<dates>.+?) # all valid strings must have some kind of date (?:\s+(?:at\s+)? # the keyword at is optional in front of a time (?<time>\d{1,2}(?::\d{1,2})?))? # a time is optional and pretty permissive by personal convention should be hh:mm (?:\s+starting\s+(?<starting>.+?))? # optional starting date (?:\s+ending\s+(?<ending>.+?))? # optional ending date $}x end |
#parse ⇒ Object
12 13 |
# File 'lib/todoist/date_parser.rb', line 12 def parse end |