Skip to content

Commit

Permalink
Fixed some code review findings
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborbata committed Mar 18, 2021
1 parent a7dcf75 commit 78370ab
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 56 deletions.
13 changes: 3 additions & 10 deletions bin/todo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
require 'date'

class Todo

COLOR_CODES = {
black: 30,
red: 31,
Expand Down Expand Up @@ -177,7 +176,6 @@ def setup
next_7_days = (0..6).map do |day| @today + day end
@due_date_days = next_7_days.map do |day| day.strftime('%A').downcase end
due_dates_for_queries = next_7_days.map do |day| day.strftime(DATE_FORMAT) end

@queries = {
':active' => lambda do |task| /(new|started|blocked)/.match(task[:state]) end,
':done' => lambda do |task| 'done' == task[:state] end,
Expand Down Expand Up @@ -380,24 +378,19 @@ def filter_tasks(tasks, patterns)
end
items[num] = task if match
end
return items
items
end

def colorize(text, color)
"\e[#{COLOR_CODES[color] || 37}m#{text}\e[0m"
end

def convert_due_date(date)
due = nil
day_index = @due_date_days.index(date.to_s.downcase) ||
DUE_DATE_DAYS_SIMPLE.index(date.to_s.downcase) ||
@due_date_days.map do |day| day[0..2] end.index(date.to_s.downcase)
if day_index
due = (@today + day_index).strftime(DATE_FORMAT)
else
due = date.nil? || date.empty? ? nil : Date.strptime(date, DATE_FORMAT).strftime(DATE_FORMAT)
end
return due
return (@today + day_index).strftime(DATE_FORMAT) if day_index
date.nil? || date.empty? ? nil : Date.strptime(date, DATE_FORMAT).strftime(DATE_FORMAT)
end
end

Expand Down
2 changes: 1 addition & 1 deletion node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "todo-jsonl",
"version": "0.1.32",
"version": "0.1.33",
"description": "todo list manager on the command-line inspired by todo.txt using the jsonl format",
"main": "todo.js",
"bin": {
Expand Down
18 changes: 9 additions & 9 deletions node/todo.js

Large diffs are not rendered by default.

14 changes: 4 additions & 10 deletions node/todo.js.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
require 'date'

class Todo

COLOR_CODES = {
black: 30,
red: 31,
Expand Down Expand Up @@ -66,6 +65,7 @@ class Todo
}

DATE_FORMAT = '%Y-%m-%d'
DATE_PATTERN = /^[1-9]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/
DUE_DATE_DAYS_SIMPLE = ['today', 'tomorrow']
DUE_DATE_TAG_PATTERN = /(^| )due:([a-zA-Z0-9-]+)/
CONTEXT_TAG_PATTERN = /(^| )[@+][\w-]+/
Expand Down Expand Up @@ -177,7 +177,6 @@ def setup
next_7_days = (0..6).map do |day| @today + day end
@due_date_days = next_7_days.map do |day| day.strftime('%A').downcase end
due_dates_for_queries = next_7_days.map do |day| day.strftime(DATE_FORMAT) end

@queries = {
':active' => lambda do |task| /(new|started|blocked)/.match(task[:state]) end,
':done' => lambda do |task| 'done' == task[:state] end,
Expand Down Expand Up @@ -395,24 +394,19 @@ def filter_tasks(tasks, patterns)
end
items[num] = task if match
end
return items
items
end

def colorize(text, color)
`'\u001b[' + #{COLOR_CODES[color] || 37} + 'm' + #{text} + '\u001b[0m'`
end

def convert_due_date(date)
due = nil
day_index = @due_date_days.index(date.to_s.downcase) ||
DUE_DATE_DAYS_SIMPLE.index(date.to_s.downcase) ||
@due_date_days.map do |day| day[0..2] end.index(date.to_s.downcase)
if day_index
due = (@today + day_index).strftime(DATE_FORMAT)
else
due = date.nil? || date.empty? ? nil : Date.parse(/^\d{4}-\d{2}-\d{2}$/.match(date).to_s).strftime(DATE_FORMAT)
end
return due
return (@today + day_index).strftime(DATE_FORMAT) if day_index
date.nil? || date.empty? ? nil : Date.parse(DATE_PATTERN.match(date).to_s).strftime(DATE_FORMAT)
end
end

Expand Down
4 changes: 2 additions & 2 deletions todo.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Gem::Specification.new do |s|
s.name = 'todo-jsonl'
s.version = '0.1.32'
s.date = '2021-03-17'
s.version = '0.1.33'
s.date = '2021-03-18'
s.summary = 'todo list manager on the command-line inspired by todo.txt using the jsonl format'
s.authors = ['Gabor Bata']
s.homepage = 'https://github.com/gaborbata/todo'
Expand Down
22 changes: 11 additions & 11 deletions web/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion web/app.js.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

`
var term = new VanillaTerminal({
'welcome': '<u>todo list manager</u> REPL v0.1.32<br>Type "help" or "copyright" for more information.<br><br>',
'welcome': '<u>todo list manager</u> REPL v0.1.33<br>Type "help" or "copyright" for more information.<br><br>',
'defaultCallback': default_callback,
'prompt': 'todo',
'commands': {
Expand Down
17 changes: 5 additions & 12 deletions web/todo.js.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
require 'date'

class Todo

COLOR_CODES = {
black: 30,
red: 31,
Expand Down Expand Up @@ -66,11 +65,12 @@ class Todo
}

DATE_FORMAT = '%Y-%m-%d'
DATE_PATTERN = /^[1-9]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/
DUE_DATE_DAYS_SIMPLE = ['today', 'tomorrow']
DUE_DATE_TAG_PATTERN = /(^| )due:([a-zA-Z0-9-]+)/
CONTEXT_TAG_PATTERN = /(^| )[@+][\w-]+/
PRIORITY_FLAG = '*'
TODO_FILE = "todo.jsonl"
TODO_FILE = 'todo.jsonl'

def execute(arguments)
@text_buffer = []
Expand Down Expand Up @@ -189,7 +189,6 @@ def setup
next_7_days = (0..6).map do |day| @today + day end
@due_date_days = next_7_days.map do |day| day.strftime('%A').downcase end
due_dates_for_queries = next_7_days.map do |day| day.strftime(DATE_FORMAT) end

@queries = {
':active' => lambda do |task| /(new|started|blocked)/.match(task[:state]) end,
':done' => lambda do |task| 'done' == task[:state] end,
Expand All @@ -206,7 +205,6 @@ def setup
def load_tasks(item_to_check = nil)
count = 0
tasks = {}

todo_jsonl = `window.localStorage.getItem(#{TODO_FILE}) || ''`
if !todo_jsonl.empty?
todo_jsonl.split("\n").each do |line|
Expand Down Expand Up @@ -376,23 +374,18 @@ def filter_tasks(tasks, patterns)
end
items[num] = task if match
end
return items
items
end

def colorize(text, color)
"\e[#{COLOR_CODES[color] || 37}m#{text}\e[0m"
end

def convert_due_date(date)
due = nil
day_index = @due_date_days.index(date.to_s.downcase) ||
DUE_DATE_DAYS_SIMPLE.index(date.to_s.downcase) ||
@due_date_days.map do |day| day[0..2] end.index(date.to_s.downcase)
if day_index
due = (@today + day_index).strftime(DATE_FORMAT)
else
due = date.nil? || date.empty? ? nil : Date.parse(/^\d{4}-\d{2}-\d{2}$/.match(date).to_s).strftime(DATE_FORMAT)
end
return due
return (@today + day_index).strftime(DATE_FORMAT) if day_index
date.nil? || date.empty? ? nil : Date.parse(DATE_PATTERN.match(date).to_s).strftime(DATE_FORMAT)
end
end

0 comments on commit 78370ab

Please sign in to comment.