Class: LogworkManager::Move

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

Overview

Command for move action

Instance Method Summary collapse

Constructor Details

#initialize(arguments, workday_hours) ⇒ Move

Returns a new instance of Move.



85
86
87
88
89
90
91
# File 'lib/logwork_manager/command.rb', line 85

def initialize(arguments, workday_hours)
  super(arguments, workday_hours)
  raise LogworkException::ArgumentError, "Wrong numberof arguments #{@args}" if @args.size != 2

  @pos1 = Integer(@args[0])
  @pos2 = Integer(@args[1])
end

Instance Method Details

#update_issues(issues, _) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/logwork_manager/command.rb', line 93

def update_issues(issues, _)
  check_out_of_bounds(issues, @pos1)
  check_out_of_bounds(issues, @pos2)
  raise LogworkException::ArgumentError, "Pos 1 and pos 2 can not be equal #{@args}" if @pos1 == @pos2

  # swapping positions
  temp = issues[@pos1]
  issues[@pos1] = issues[@pos2]
  issues[@pos2] = temp

  issues
end