Module: Improves::Moveable

Included in:
AdvancedMove, AnotherMove, HavenMove, PlaybookMove
Defined in:
app/services/improves/moveable.rb

Overview

Methods supporting a Move-type Improvable Supports a single Move or many Moves

Instance Method Summary collapse

Instance Method Details

#already_advanced_moves?Boolean

Check if moves are already advanced

Returns:

  • (Boolean)

24
25
26
# File 'app/services/improves/moveable.rb', line 24

def already_advanced_moves?
  @hunter.hunters_moves.where(move: @moves).any?(&:advanced?)
end

#hunter_move_exists?Boolean

Returns:

  • (Boolean)

33
34
35
36
37
# File 'app/services/improves/moveable.rb', line 33

def hunter_move_exists?
  return false if invalid_move?
  return false if @move.type == 'Moves::Basic'
  @hunter.moves.include?(@move)
end

#invalid_move?Boolean

Check if move(s) have been found

Returns:

  • (Boolean)

29
30
31
# File 'app/services/improves/moveable.rb', line 29

def invalid_move?
  @move.nil? && @moves.blank?
end

#moveObject


7
8
9
10
# File 'app/services/improves/moveable.rb', line 7

def move
  @move ||=
    Move.find_by(id: @hunters_improvement.improvable&.dig('move', 'id'))
end

#movesObject


12
13
14
15
16
# File 'app/services/improves/moveable.rb', line 12

def moves
  @moves ||=
    Move.where(id:
      @hunters_improvement.improvable&.dig('moves')&.pluck('id'))
end

#not_basic_moves?Boolean

Checks any moves are not basic relies on moves_count

Returns:

  • (Boolean)

46
47
48
# File 'app/services/improves/moveable.rb', line 46

def not_basic_moves?
  @moves.where.not(type: 'Moves::Basic').count.positive?
end

#not_haven_move?Boolean

Returns:

  • (Boolean)

39
40
41
42
# File 'app/services/improves/moveable.rb', line 39

def not_haven_move?
  return false if invalid_move?
  @move.present? && !@move.haven
end

#playbook_move_match?Boolean

Returns:

  • (Boolean)

55
56
57
58
# File 'app/services/improves/moveable.rb', line 55

def playbook_move_match?
  return false if invalid_move?
  @improvement.playbook == @move.playbook
end

#playbook_move_mismatch?Boolean

Returns:

  • (Boolean)

50
51
52
53
# File 'app/services/improves/moveable.rb', line 50

def playbook_move_mismatch?
  return false if invalid_move?
  !playbook_move_match?
end

#valid?Boolean

Returns:

  • (Boolean)

18
19
20
21
# File 'app/services/improves/moveable.rb', line 18

def valid?
  super
  check :invalid_move?, :move, 'not found'
end