Class: Brakeman::Messages::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/brakeman/messages.rb

Overview

Class to represent a list of message types

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Message

Returns a new instance of Message.



57
58
59
60
61
62
63
64
65
66
# File 'lib/brakeman/messages.rb', line 57

def initialize *args
  @parts = args.map do |a|
    case a
    when String, Symbol
      Brakeman::Messages::Plain.new(a.to_s)
    else
      a
    end
  end
end

Instance Method Details

#<<(msg) ⇒ Object



68
69
70
71
72
73
74
# File 'lib/brakeman/messages.rb', line 68

def << msg
  if msg.is_a? String
    @parts << Brakeman::Messages::Plain.new(msg)
  else
    @parts << msg
  end
end

#to_htmlObject



88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/brakeman/messages.rb', line 88

def to_html
  require 'cgi'

  output = @parts.map(&:to_html).join

  case @parts.first
  when Brakeman::Messages::Code, Brakeman::Messages::Literal, Brakeman::Messages::Version
  else
    output[0] = output[0].capitalize
  end

  output
end

#to_sObject



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/brakeman/messages.rb', line 76

def to_s
  output = @parts.map(&:to_s).join

  case @parts.first
  when Brakeman::Messages::Code, Brakeman::Messages::Literal, Brakeman::Messages::Version
  else
    output[0] = output[0].capitalize
  end

  output
end