Class: PoliticalForce

Inherits:
ApplicationRecord show all
Includes:
Checkable, RequiredUniqueName, RequiredUniqueSlug
Defined in:
app/models/political_force.rb

Overview

Political force

Attributes:

candidates_count [integer]
created_at [DateTime]
data [jsonb]
flare [string], optional
image [string], optional
name [string]
slug [string]
sync_state [JSON]
updated_at [DateTime]
uuid [UUID]

Constant Summary collapse

FLARE_LIMIT =
20
NAME_LIMIT =
100
SLUG_LIMIT =
20
SLUG_PATTERN =
/\A[a-z][-_a-z]+[a-z]\z/.freeze
SLUG_PATTERN_HTML =
'^[a-zA-Z][-_a-zA-Z]+[a-zA-Z]$'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.entity_parametersObject



44
45
46
# File 'app/models/political_force.rb', line 44

def self.entity_parameters
  %i[flare image name slug]
end

Instance Method Details

#add_candidate(entity) ⇒ Object

Parameters:



54
55
56
# File 'app/models/political_force.rb', line 54

def add_candidate(entity)
  candidate_political_forces.create(candidate: entity)
end

#candidate?(entity) ⇒ Boolean

Parameters:

Returns:

  • (Boolean)


49
50
51
# File 'app/models/political_force.rb', line 49

def candidate?(entity)
  candidate_political_forces.where(candidate: entity).exists?
end

#remove_candidate(entity) ⇒ Object

Parameters:



59
60
61
# File 'app/models/political_force.rb', line 59

def remove_candidate(entity)
  candidate_political_forces.where(candidate: entity).destroy_all
end