Sha256: 3a1acc55e0f38a7dc51f026291d8cf674e712bce4539c1d69853c2f54ff749ab

Contents?: true

Size: 1.73 KB

Versions: 2

Compression:

Stored size: 1.73 KB

Contents

module Vedeu

  # Combines stored interface layout/geometry with an interface view/buffer
  # to create a single view to be sent to the terminal for output.
  #
  # @api private
  class Compositor

    include Common

    # Convenience method to initialize a new Compositor and call its {#compose}
    # method.
    #
    # @return [Compositor]
    # @see #initialize
    def self.compose(interface, buffer)
      new(interface, buffer).compose
    end

    # Initialize a new Compositor.
    #
    # @param interface [Hash] The attributes of the interface to be refreshed.
    # @param buffer [Hash] The atttributes of the buffer to refresh the
    #   interface with.
    # @return [Compositor]
    def initialize(interface, buffer)
      @interface = interface
      @buffer    = buffer
    end

    # Return a new instance of Interface built by combining the buffer content
    # attributes with the stored interface attributes.
    #
    # @return [Array<Hash>] The updated interface attributes.
    def compose
      buffer.content.each do |content|
        change_geometry(content)

        interface[:lines] = content[:lines]
        change_colour(content)
        change_style(content)

        Output.render(Interface.new(interface))
      end
    end

    private

    attr_reader :interface, :buffer

    def change_colour(content)
      interface[:colour] = content[:colour] if defined_value?(content[:colour])
    end

    def change_geometry(content)
      content[:geometry].each do |k, v|
        interface[:geometry][k] = v if defined_value?(k)
      end if defined_value?(content[:geometry])
    end

    def change_style(content)
      interface[:style] = content[:style] if defined_value?(content[:style])
    end

  end # Compositor

end # Vedeu

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
vedeu-0.2.12 lib/vedeu/output/compositor.rb
vedeu-0.2.11 lib/vedeu/output/compositor.rb