Class: Pechkin::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/pechkin/message.rb

Overview

Message object

TBD

Instance Method Summary collapse

Constructor Details

#initialize(message) ⇒ Message

Returns a new instance of Message.



6
7
8
# File 'lib/pechkin/message.rb', line 6

def initialize(message)
  @message = message
end

Instance Method Details

#prepare(data) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/pechkin/message.rb', line 10

def prepare(data)
  data = (@message['variables'] || {}).merge(data)
  # Find message and try substitute values to message parameters.
  message_config = render(data, substitute(data, @message))
  text = ''
  text = message_config.delete('template') if message_config.key?('template')

  [message_config, text]
end

#to_hObject



20
21
22
# File 'lib/pechkin/message.rb', line 20

def to_h
  Marshal.load(Marshal.dump(@message))
end