Sha256: a6b62f14a8f172f008cb33e3196ef64a0d1f4be239c43eb3c74adc7a4c4757a1

Contents?: true

Size: 1.23 KB

Versions: 7

Compression:

Stored size: 1.23 KB

Contents

module Vedeu

  module Output

    # Write a string directly to the terminal at defined coordinates.
    #
    class Direct

      # @param value [String]
      # @param x [Fixnum]
      # @param y [Fixnum]
      # @return [String]
      def self.write(value:, x:, y:)
        new(value: value, x: x, y: y).write
      end

      # Returns a new instance of Vedeu::Output::Direct.
      #
      # @param value [String]
      # @param x [Fixnum]
      # @param y [Fixnum]
      # @return [Vedeu::Output::Direct]
      def initialize(value:, x:, y:)
        @value = value || ''
        @x     = x     || 1
        @y     = y     || 1
      end

      # @return [String]
      def write
        Vedeu::Terminal.output(output)

        output
      end

      protected

      # @attribute [r] value
      # @return [String]
      attr_reader :value

      # @attribute [r] x
      # @return [Fixnum]
      attr_reader :x

      # @attribute [r] y
      # @return [Fixnum]
      attr_reader :y

      private

      # @return [String]
      def output
        (Array(position) + Array(value)).join
      end

      # @return [String]
      def position
        Vedeu::Geometry::Position.new(y, x).to_s
      end

    end # Direct

  end # Output

end # Vedeu

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
vedeu-0.6.15 lib/vedeu/output/direct.rb
vedeu-0.6.14 lib/vedeu/output/direct.rb
vedeu-0.6.13 lib/vedeu/output/direct.rb
vedeu-0.6.12 lib/vedeu/output/direct.rb
vedeu-0.6.11 lib/vedeu/output/direct.rb
vedeu-0.6.10 lib/vedeu/output/direct.rb
vedeu-0.6.9 lib/vedeu/output/direct.rb