Class: Todoist::DateParser

Inherits:
Object
  • Object
show all
Defined in:
lib/todoist/date_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#datesObject (readonly)

Returns the value of attribute dates.



3
4
5
# File 'lib/todoist/date_parser.rb', line 3

def dates
  @dates
end

#due_partsObject (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_regexObject



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

#parseObject



12
13
# File 'lib/todoist/date_parser.rb', line 12

def parse
end