Class: Wlog::EditHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/wlog/ui/edit_handler.rb

Overview

Author:

  • Simon Symeonidis

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#issueObject (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'.

Parameters:

  • time_str

    is the time in string format



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.

Parameters:

  • time

    is the date-time in string format (eg Oct 28)

Returns:

  • nothing - we’re just setting if the data format is ok



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

Parameters:

  • time_str

    The time that we want to kind of sanitize

Returns:

  • a Time object which is set to 9am on that day if no time is provided



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