Class: MessageFunction

Inherits:
Object
  • Object
show all
Defined in:
app/models/message_function.rb

Constant Summary collapse

@@functions =
[
  MessageFunction.new('welcome', 'Welcome'),
  MessageFunction.new('invitation', 'Invitation' ),
  MessageFunction.new('group_welcome', 'Group welcome'),
  MessageFunction.new('group_invitation', 'Group invitation' ),
  MessageFunction.new('password_reset', 'Password instructions'),
  MessageFunction.new('activation', 'Activation instructions')
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, description = '') ⇒ MessageFunction

Returns a new instance of MessageFunction.



4
5
6
# File 'app/models/message_function.rb', line 4

def initialize(name, description='')
  @name = name
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



2
3
4
# File 'app/models/message_function.rb', line 2

def name
  @name
end

Class Method Details

.[](value) ⇒ Object



24
25
26
27
# File 'app/models/message_function.rb', line 24

def self.[](value)
  return if value.blank?
  @@functions.find { |function| function.symbol == value.to_s.downcase.intern }
end

.add(name, description = '') ⇒ Object



29
30
31
# File 'app/models/message_function.rb', line 29

def self.add(name, description='')
  @@functions.push(MessageFunction.new(name, description)) unless MessageFunction[name]
end

.find_allObject



33
34
35
# File 'app/models/message_function.rb', line 33

def self.find_all
  @@functions.dup
end

Instance Method Details

#descriptionObject



16
17
18
# File 'app/models/message_function.rb', line 16

def description
  I18n.t("message_functions.#{@name}")
end

#humanizeObject



20
21
22
# File 'app/models/message_function.rb', line 20

def humanize
  to_s.gsub('_', ' ')
end

#symbolObject



8
9
10
# File 'app/models/message_function.rb', line 8

def symbol
  @name.to_s.downcase.intern
end

#to_sObject



12
13
14
# File 'app/models/message_function.rb', line 12

def to_s
  @name
end