Class: Arkaan::Campaigns::Character

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Timestamps
Defined in:
lib/arkaan/campaigns/character.rb

Overview

A character sheet represents a character played by a player in a campaign.

Author:

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dataHash

Returns the heart of the Arkaan::Campaigns::Character class, the polymorphic data representing all the fields of a character sheet are validated using the validator of the associated plugin, and created/updated with the corresponding form.

Returns:

  • (Hash)

    the heart of the Arkaan::Campaigns::Character class, the polymorphic data representing all the fields of a character sheet are validated using the validator of the associated plugin, and created/updated with the corresponding form.



17
# File 'lib/arkaan/campaigns/character.rb', line 17

field :data, type: Hash, default: {}

#invitationArkaan::Campaigns::Invitation

Returns the invitation of the player playing this character.

Returns:



21
# File 'lib/arkaan/campaigns/character.rb', line 21

belongs_to :invitation, class_name: 'Arkaan::Campaigns::Invitation', inverse_of: :characters

#selectedBoolean

Returns TRUE if the sheet is currently selected by the player, FALSE otherwise.

Returns:

  • (Boolean)

    TRUE if the sheet is currently selected by the player, FALSE otherwise.



11
# File 'lib/arkaan/campaigns/character.rb', line 11

field :selected, type: Boolean, default: false

Instance Method Details

#campaignObject



29
30
31
# File 'lib/arkaan/campaigns/character.rb', line 29

def campaign
  invitation.campaign
end

#playerArkaan::Account

Returns the player linked to this character.

Returns:

  • (Arkaan::Account)

    the account of the player incarnating this character.



25
26
27
# File 'lib/arkaan/campaigns/character.rb', line 25

def player
  invitation.
end

#select!Object

Puts the selected flag to TRUE for this character and to FALSE for all the other characters for the same player in the same campaign.



35
36
37
38
39
40
41
42
# File 'lib/arkaan/campaigns/character.rb', line 35

def select!
  invitation.characters.each do |character|
    character.update_attribute(:selected, false)
    character.save!
  end
  update_attribute(:selected, true)
  save!
end