Class: Wlog::EditHandler
- Inherits:
-
Object
- Object
- Wlog::EditHandler
- Defined in:
- lib/wlog/ui/edit_handler.rb
Overview
Instance Attribute Summary collapse
-
#issue ⇒ Object
readonly
Pass the issue from the previous ui to this one.
Instance Method Summary collapse
-
#edit_reported_time(time_str) ⇒ Object
Edit the reported date of an issue, given a date string in the format of ‘Oct 28’.
-
#edit_time(time) ⇒ Object
Small helper to parse the due date when editing the dates of issues.
-
#edit_what(terms_a) ⇒ Object
Command comes in as edit <…>.
-
#initialize(issue) ⇒ EditHandler
constructor
A new instance of EditHandler.
-
#time_handle(time_str) ⇒ Object
TODO fix me.
Constructor Details
#initialize(issue) ⇒ EditHandler
Returns a new instance of EditHandler.
9 10 11 12 |
# File 'lib/wlog/ui/edit_handler.rb', line 9 def initialize(issue) @issue = issue @strmaker = SysConfig.string_decorator end |
Instance Attribute Details
#issue ⇒ Object (readonly)
Pass the issue from the previous ui to this one. This ui modifies
76 77 78 |
# File 'lib/wlog/ui/edit_handler.rb', line 76 def issue @issue end |
Instance Method Details
#edit_reported_time(time_str) ⇒ Object
Edit the reported date of an issue, given a date string in the format of
'Oct 28'.
56 57 58 59 60 61 62 63 64 |
# File 'lib/wlog/ui/edit_handler.rb', line 56 def edit_reported_time(time_str) date_time = time_handle(time_str) @issue.reported_date = date_time.to_time @issue.update puts @strmaker.green('Updated reported date') rescue ArgumentError $stderr.puts @strmaker.red \ "Invalid date/time format. Try format like 'Oct 28'" end |
#edit_time(time) ⇒ Object
Small helper to parse the due date when editing the dates of issues.
44 45 46 47 48 49 50 51 |
# File 'lib/wlog/ui/edit_handler.rb', line 44 def edit_time(time) date_time = time_handle(time) @issue.update(:due_date => date_time) puts @strmaker.green('Updated due date') rescue ArgumentError $stderr.puts @strmaker.red \ "Invalid date/time format. Try format like 'Oct 28'" end |
#edit_what(terms_a) ⇒ Object
Command comes in as edit <…>. This definition will check what comes next and invoke the proper method to execute.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/wlog/ui/edit_handler.rb', line 16 def edit_what(terms_a) param = (terms_a.drop 1).join ' ' case terms_a[0] when /^title/ @issue.update(:description => param) when /^desc/ @issue.update(:long_description => param) when /^due/ edit_time(param) when /^reported/ edit_reported_time(param) else $stdout.puts "Usage: " $stdout.puts " edit title - to edit the title" $stdout.puts " edit desc - to edit the long description" $stdout.puts " edit due - to edit the due date" $stdout.puts " edit time - to edit the time" end end |
#time_handle(time_str) ⇒ Object
TODO fix me
70 71 72 73 |
# File 'lib/wlog/ui/edit_handler.rb', line 70 def time_handle(time_str) date_time = DateTime.parse(time_str) date_time = DateTime.parse(time_str + ' 9:00') if date_time.hour == 0 end |