Class: Pwl::Message

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

Direct Known Subclasses

ErrorMessage

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template, exit_code = 0, default_replacements = {}) ⇒ Message

Returns a new instance of Message.



17
18
19
20
21
# File 'lib/pwl/message.rb', line 17

def initialize(template, exit_code = 0, default_replacements = {})
  @template = ERB.new(template)
  @exit_code = exit_code
  @default_replacements = default_replacements
end

Instance Attribute Details

#exit_codeObject (readonly)

Returns the value of attribute exit_code.



15
16
17
# File 'lib/pwl/message.rb', line 15

def exit_code
  @exit_code
end

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/pwl/message.rb', line 31

def error?
  false
end

#to_s(replacements = {}) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/pwl/message.rb', line 23

def to_s(replacements = {})
  if !replacements.any? && @default_replacements.any?
    @template.result(@default_replacements.to_binding)
  else
    @template.result(replacements.to_binding)
  end
end