Method: ActiveKit::Position::Positioner#spot_for

Defined in:
lib/active_kit/position/positioner.rb

#spot_for(position:, position_maximum_cached:) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/active_kit/position/positioner.rb', line 26

def spot_for(position:, position_maximum_cached:)
  raise "position or position_maximum_cached cannot be empty for spot_for in activekit." unless position && position_maximum_cached

  edge_position = position_maximum_cached + 1
  if position == edge_position && position == 1
    value, @reharmonize = @positioning.chair_first
  elsif position == edge_position
    value, @reharmonize = @positioning.chair_below(currvalue: self.maxivalue)
  elsif position_in_database.nil?
    value, @reharmonize = @positioning.stool_above(currvalue: currvalue(position, position_maximum_cached),
                                                       prevvalue: prevvalue(position, position_maximum_cached))
  elsif position > position_in_database
    value, @reharmonize = @positioning.stool_below(currvalue: currvalue(position, position_maximum_cached),
                                                       nextvalue: nextvalue(position, position_maximum_cached))
  else
    value, @reharmonize = @positioning.stool_above(currvalue: currvalue(position, position_maximum_cached),
                                                       prevvalue: prevvalue(position, position_maximum_cached))
  end

  value
end