Class: Kward::PromptInterface::Banner

Inherits:
Object
  • Object
show all
Defined in:
lib/kward/prompt_interface/banner.rb

Constant Summary collapse

LOGO_WIDTH =
32
LOGO_PIXEL_HEIGHT =
32
MIN_LOGO_HEIGHT =
4
LOGO_PIXELS =
Kward::Resources::AvatarKwardLogo::PIXELS
MESSAGE =
"State your business.".freeze

Instance Method Summary collapse

Constructor Details

#initialize(message:, pixels:, screen_height:, minimum_composer_rows: 3) ⇒ Banner

Returns a new instance of Banner.



14
15
16
17
18
19
20
# File 'lib/kward/prompt_interface/banner.rb', line 14

def initialize(message:, pixels:, screen_height:, minimum_composer_rows: 3)
  @message = message.to_s
  @pixels = pixels
  @screen_height = screen_height
  @minimum_composer_rows = minimum_composer_rows
  @logo_cache = {}
end

Instance Method Details

#logo_rows(width) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/kward/prompt_interface/banner.rb', line 32

def logo_rows(width)
  logo_width, logo_height = logo_dimensions(width)
  return [] unless @pixels && max_logo_height >= MIN_LOGO_HEIGHT

  key = [logo_width, logo_height]
  @logo_cache[key] ||= Kward::PixelLogo.half_block_rows_from_pixels(@pixels, width: logo_width, pixel_height: logo_height)
end

#rows(width) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/kward/prompt_interface/banner.rb', line 22

def rows(width)
  return [] unless visible?(width)

  rows = []
  rows.concat(centered_image_rows(width)) if image_visible?(width)
  rows << align_plain_row(@message, width) unless @message.empty?
  rows << ""
  rows
end