Class: Improvements::HavenMove

Inherits:
Improvement show all
Defined in:
app/models/improvements/haven_move.rb

Overview

This is for Improvements like “Add an option to your haven”

Constant Summary

Constants inherited from Improvement

Improvement::IMPROVEMENT_TYPES

Instance Attribute Summary

Attributes inherited from Improvement

#advanced, #created_at, #description, #id, #playbook_id, #rating, #stat_limit, #type, #updated_at

Instance Method Summary collapse

Methods inherited from Improvement

advanced_eligible?, policy_class

Methods inherited from ApplicationRecord

policy_class

Instance Method Details

#configured_haven(hunters_improvement) ⇒ Object


37
38
39
40
41
42
# File 'app/models/improvements/haven_move.rb', line 37

def configured_haven(hunters_improvement)
  Haven.find(hunters_improvement.improvable&.dig('haven', 'id'))
rescue ActiveRecord::RecordNotFound => e
  hunters_improvement.errors.add(:improvable, e.message)
  false
end

#configured_move(hunters_improvement) ⇒ Object


44
45
46
47
48
49
# File 'app/models/improvements/haven_move.rb', line 44

def configured_move(hunters_improvement)
  Move.find(hunters_improvement.improvable&.dig('move', 'id'))
rescue ActiveRecord::RecordNotFound => e
  hunters_improvement.errors.add(:improvable, e.message)
  false
end

#improvable_options(hunter) ⇒ Object


55
56
57
58
59
60
61
62
63
# File 'app/models/improvements/haven_move.rb', line 55

def improvable_options(hunter)
  moves = Move.where.not(id: hunter.moves.select(:id))
              .haven
              .select(:id, :name, :description)
  {
    move: { data: moves, count: option_count },
    haven: { data: Haven.all, count: 1 }
  }
end

#option_countObject


51
52
53
# File 'app/models/improvements/haven_move.rb', line 51

def option_count
  1 # Flake gets 2 and a Haven
end