Class: Uh::Layout::ClientColumnMover

Inherits:
Object
  • Object
show all
Defined in:
lib/uh/layout/client_column_mover.rb

Instance Method Summary collapse

Constructor Details

#initialize(columns, columns_max_count) ⇒ ClientColumnMover

Returns a new instance of ClientColumnMover.



4
5
6
7
# File 'lib/uh/layout/client_column_mover.rb', line 4

def initialize columns, columns_max_count
  @columns            = columns
  @columns_max_count  = columns_max_count
end

Instance Method Details

#get_or_create_column(direction) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/uh/layout/client_column_mover.rb', line 17

def get_or_create_column direction
  if candidate = @columns.get(direction)
    candidate
  elsif @columns_max_count
    @columns.get direction, cycle: true
  else
    Column.new(Geo.new).tap do |o|
      case direction
        when :pred then @columns.unshift o
        when :succ then @columns << o
      end
    end
  end
end

#move_current(direction) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/uh/layout/client_column_mover.rb', line 9

def move_current direction
  @columns.current.remove client = @columns.current.current_client
  dest_column = get_or_create_column direction
  dest_column << client
  dest_column.current_client = client
  @columns.current = dest_column
end