Class: Twterm::Image::VerticalSequentialImage

Inherits:
Twterm::Image show all
Defined in:
lib/twterm/image/vertical_sequential_image.rb

Instance Method Summary collapse

Methods inherited from Twterm::Image

#!, #-, #_, #at, blank_line, #bold, #brackets, checkbox, #color, #column, cursor, #dim, empty, #line, number, #parens, plural, remaining_resource, string, toggle_switch, #underlined, whitespace

Constructor Details

#initialize(images) ⇒ VerticalSequentialImage

Returns a new instance of VerticalSequentialImage.



4
5
6
# File 'lib/twterm/image/vertical_sequential_image.rb', line 4

def initialize(images)
  @images = images
end

Instance Method Details

#append(image) ⇒ Object



12
13
14
15
# File 'lib/twterm/image/vertical_sequential_image.rb', line 12

def append(image)
  images << image
  self
end

#heightObject



17
18
19
# File 'lib/twterm/image/vertical_sequential_image.rb', line 17

def height
  images.map(&:height).reduce(0, :+)
end

#render(window) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/twterm/image/vertical_sequential_image.rb', line 21

def render(window)
  window.setpos(line, column)
  images
    .zip(images.lazy.map(&:height).scan(line, :+))
    .each { |r, l| r.at(l, column).render(window) }

  self
end

#to_sObject



30
31
32
# File 'lib/twterm/image/vertical_sequential_image.rb', line 30

def to_s
  images.map(&:to_s).join("\n")
end

#widthObject



34
35
36
# File 'lib/twterm/image/vertical_sequential_image.rb', line 34

def width
  images.map(&:width).max
end

#|(other) ⇒ Object



8
9
10
# File 'lib/twterm/image/vertical_sequential_image.rb', line 8

def |(other)
  append(other)
end