Skip to content

Commit

Permalink
Fix priority's regex to recognize priorities around dates, not just i…
Browse files Browse the repository at this point in the history
…n the beginning of the task's text
  • Loading branch information
spap committed Nov 13, 2013
1 parent 86f192b commit c3c93b5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/todo-txt/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ def self.projects_regex
end

# The regex used to match priorities.
def self.priotity_regex
/^\([A-Za-z]\)\s+/
def self.priority_regex
/(?:^|\s+)\(([A-Za-z])\)\s+/
end

# The regex used to match dates.
Expand Down Expand Up @@ -121,7 +121,7 @@ def initialize task
def text
@text ||= orig.
gsub(self.class.done_regex, '').
gsub(self.class.priotity_regex, '').
gsub(self.class.priority_regex, '').
gsub(self.class.created_on_regex, '').
gsub(self.class.contexts_regex, '').
gsub(self.class.projects_regex, '').
Expand Down Expand Up @@ -268,7 +268,7 @@ def <=> other_task
private

def orig_priority
orig =~ self.class.priotity_regex ? orig[1] : nil
@orig.match(self.class.priority_regex)[1] if @orig =~ self.class.priority_regex
end

def orig_created_on
Expand Down
5 changes: 5 additions & 0 deletions spec/todo-txt/task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
task.priority.should == nil
end

it 'should recognize priorities around dates' do
task = Todo::Task.new "x 2012-09-11 (B) 2012-03-04 This is a sweet task. @context +project"
task.priority.should == "B"
end

it 'should recognise contexts' do
task = Todo::Task.new "Hello, world! @test"
task.contexts.should == ["@test"]
Expand Down

0 comments on commit c3c93b5

Please sign in to comment.