Class: LogworkManager::CommandHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/logwork_manager/command_handler.rb

Overview

Manages the Worklog table.

Instance Method Summary collapse

Constructor Details

#initialize(workday_hours = nil) ⇒ CommandHandler

Construct

Parameters:

  • workday_hours (Integer) (defaults to: nil)

    The total hours of a workday, e.g. 8



28
29
30
# File 'lib/logwork_manager/command_handler.rb', line 28

def initialize(workday_hours = nil)
  @workday_hours = workday_hours
end

Instance Method Details

#update_worklog(command, issues = nil, issue_to_add: nil) ⇒ Array<WorklogIssue>

Updates the daily worklog table by applying the given command.

Parameters:

  • command (String)

    The command that will be applied to the issues parameter. The available commands are:

    • move m [pos1] [pos2] (e.g. 'm 2 1', it moves the issue from position 1 to position 2 (swipes issues)

    • duration d [pos] [duration] (e.g. 'd 3 30m', it changes the duration of the issue at position 3 to 30 minutes). Pass 'auto' to automatically expand the duration to fill the required working hours.

    • remove r [pos] (e.g 'r 3', remove from the position 3)

    • insert i [pos] (e.g 'i 3', insert into position 3. Pos parameter can be omitted and

    the new issue will be inserted at the end )

  • issues (Array<WorklogIssue>) (defaults to: nil)

    The array of worklog issues.

Returns:

  • (Array<WorklogIssue>)

    The updated array of work log issues.

Raises:

  • LogworkException::InvalidCommand

  • LogworkException::ArgumentError



46
47
48
49
50
51
# File 'lib/logwork_manager/command_handler.rb', line 46

def update_worklog(command, issues = nil, issue_to_add: nil)
  command_found = get_command(command.strip)
  raise LogworkException::InvalidCommand, "Wrong command" if command.nil? || command.empty? || command_found.nil?

  command_found.update_issues(issues, issue_to_add)
end