notebook/app/models/character.rb
2016-10-01 17:35:59 +02:00

84 lines
2.0 KiB
Ruby

##
# = char-ac-ter
# == /'kerekter/
# _noun_
#
# 1. a person in a User's story.
#
# exists within a Universe.
class Character < ActiveRecord::Base
validates :name, presence: true
belongs_to :user
validates :user_id, presence: true
belongs_to :universe
include HasPrivacy
include HasContentGroupers
include Serendipitous::Concern
# Characters
relates :fathers, with: :fatherships
relates :mothers, with: :motherships
relates :siblings, with: :siblingships
relates :spouses, with: :marriages
relates :children, with: :childrenships
relates :best_friends, with: :best_friendships
relates :archenemies, with: :archenemyship
# Locations
relates :birthplaces, with: :birthings
# Items
relates :favorite_items, with: :ownerships, where: { favorite: true }
scope :is_public, -> { eager_load(:universe).where('characters.privacy = ? OR universes.privacy = ?', 'public', 'public') }
def description
role
end
def self.color
'red'
end
def self.icon
'group'
end
def self.attribute_categories
{
overview: {
icon: 'info',
attributes: %w(name role gender age universe_id)
},
looks: {
icon: 'face',
attributes: %w(weight height haircolor hairstyle facialhair eyecolor race skintone bodytype identmarks)
},
social: {
icon: 'groups',
attributes: %w(best_friends archenemies religion politics prejudices occupation)
},
# TODO: remove schema for mannerisms
history: {
icon: 'info',
attributes: %w(birthday birthplaces education background)
},
faves: {
icon: 'star',
attributes: %w(fave_color fave_food fave_possession fave_weapon fave_animal)
},
family: {
icon: 'face',
attributes: %w(mothers fathers spouses siblings children)
},
notes: {
icon: 'edit',
attributes: %w(notes private_notes)
}
}
end
end