Class: Decidim::BulletinBoard::MessageIdentifier

Inherits:
Object
  • Object
show all
Defined in:
lib/decidim/bulletin_board/message_identifier.rb

Constant Summary collapse

AUTHOR_TYPE =
{
  a: :authority,
  b: :bulletin_board,
  t: :trustee,
  v: :voter
}.freeze
INVERTED_AUTHOR_TYPE =
AUTHOR_TYPE.invert.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message_id) ⇒ MessageIdentifier

Returns a new instance of MessageIdentifier.



15
16
17
# File 'lib/decidim/bulletin_board/message_identifier.rb', line 15

def initialize(message_id)
  @message_id = message_id
end

Class Method Details

.format(unique_election_id, type_subtype, author_type, author_id) ⇒ Object



68
69
70
# File 'lib/decidim/bulletin_board/message_identifier.rb', line 68

def format(unique_election_id, type_subtype, author_type, author_id)
  "#{unique_election_id}.#{type_subtype}+#{INVERTED_AUTHOR_TYPE[author_type]}.#{author_id}"
end

.unique_election_id(authority_slug, election_id) ⇒ Object



72
73
74
# File 'lib/decidim/bulletin_board/message_identifier.rb', line 72

def unique_election_id(authority_slug, election_id)
  "#{authority_slug}.#{election_id}"
end

Instance Method Details

#author_idObject



35
36
37
# File 'lib/decidim/bulletin_board/message_identifier.rb', line 35

def author_id
  @author_id ||= author.last
end

#author_typeObject



31
32
33
# File 'lib/decidim/bulletin_board/message_identifier.rb', line 31

def author_type
  @author_type ||= AUTHOR_TYPE[author.first.to_sym]
end

#authority_idObject



39
40
41
# File 'lib/decidim/bulletin_board/message_identifier.rb', line 39

def authority_id
  @authority_id ||= elements[0]
end

#election_idObject



43
44
45
# File 'lib/decidim/bulletin_board/message_identifier.rb', line 43

def election_id
  @election_id ||= elements[0..1].join(".")
end

#from_authority?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/decidim/bulletin_board/message_identifier.rb', line 19

def from_authority?
  author_type == :authority
end

#from_trustee?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/decidim/bulletin_board/message_identifier.rb', line 23

def from_trustee?
  author_type == :trustee
end

#from_voter?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/decidim/bulletin_board/message_identifier.rb', line 27

def from_voter?
  author_type == :voter
end

#subtypeObject



51
52
53
# File 'lib/decidim/bulletin_board/message_identifier.rb', line 51

def subtype
  @subtype ||= elements[3]
end

#to_sObject



59
60
61
# File 'lib/decidim/bulletin_board/message_identifier.rb', line 59

def to_s
  @message_id
end

#typeObject



47
48
49
# File 'lib/decidim/bulletin_board/message_identifier.rb', line 47

def type
  @type ||= elements[2]
end

#type_subtypeObject



55
56
57
# File 'lib/decidim/bulletin_board/message_identifier.rb', line 55

def type_subtype
  @type_subtype ||= [type, subtype].compact.join(".")
end

#unique_trustee_id(authority_slug, trustee_name) ⇒ Object



63
64
65
# File 'lib/decidim/bulletin_board/message_identifier.rb', line 63

def unique_trustee_id(authority_slug, trustee_name)
  "#{authority_slug}.#{trustee_name}"
end