Class: Twterm::Image::HorizontalSequentialImage

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

Instance Method Summary collapse

Methods inherited from Twterm::Image

#!, #at, blank_line, #bold, #brackets, checkbox, #color, #column, cursor, empty, #line, number, #parens, plural, remaining_resource, string, whitespace, #|

Constructor Details

#initialize(images) ⇒ HorizontalSequentialImage

Returns a new instance of HorizontalSequentialImage.



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

def initialize(images)
  @images = images
end

Instance Method Details

#-(other) ⇒ Object



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

def -(other)
  append(other)
end

#append(image) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/twterm/image/horizontal_sequential_image.rb', line 12

def append(image)
  if image.is_a?(self.class)
    @images += image.images
  else
    images << image
  end

  self
end

#heightObject



22
23
24
# File 'lib/twterm/image/horizontal_sequential_image.rb', line 22

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

#render(window) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/twterm/image/horizontal_sequential_image.rb', line 26

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

  self
end

#to_sObject



35
36
37
# File 'lib/twterm/image/horizontal_sequential_image.rb', line 35

def to_s
  images.map(&:to_s).join
end

#widthObject



39
40
41
# File 'lib/twterm/image/horizontal_sequential_image.rb', line 39

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