Class: Dsu::Views::Shared::Message
- Inherits:
-
Object
- Object
- Dsu::Views::Shared::Message
- Includes:
- Support::ColorThemable
- Defined in:
- lib/dsu/views/shared/message.rb
Constant Summary collapse
- MESSAGE_TYPES =
i[error info success warning].freeze
Instance Method Summary collapse
-
#initialize(messages:, message_type:, options: {}) ⇒ Message
constructor
A new instance of Message.
- #render ⇒ Object
- #to_s ⇒ Object
Methods included from Support::ColorThemable
apply_theme, #prompt_with_options
Constructor Details
#initialize(messages:, message_type:, options: {}) ⇒ Message
Returns a new instance of Message.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/dsu/views/shared/message.rb', line 13 def initialize(messages:, message_type:, options: {}) = [] unless .is_a?(Array) = .select(&:present?) validate_arguments!(, , ) = = = || {} = color_theme.public_send() @header = [:header] @ordered_list = .fetch(:ordered_list, true) end |
Instance Method Details
#render ⇒ Object
27 28 29 |
# File 'lib/dsu/views/shared/message.rb', line 27 def render output_stream.puts to_s end |
#to_s ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/dsu/views/shared/message.rb', line 31 def to_s return if .empty? strings = [] strings << apply_theme(header, theme_color: color_theme.header) if header.present? strings << if .one? apply_theme([0], theme_color: ) else .each_with_index.map do |, index| = "#{index + 1}. #{message}" if ordered_list? apply_theme(, theme_color: ) end end strings.flatten.join("\n") end |