Sha256: 7227c15740fde4a34da12b0a773bf01a7ae53236e3cedf17257e0877c72ff63b

Contents?: true

Size: 1.1 KB

Versions: 6

Compression:

Stored size: 1.1 KB

Contents

require 'vedeu/support/common'
require 'vedeu/support/coercions'

module Vedeu

  # Converts the style value or value collection into a terminal escape
  # sequence. Unrecognised values are discarded- an empty string is returned.
  #
  class Style

    include Vedeu::Common
    include Vedeu::Coercions

    # @!attribute [rw] value
    # @return [String|Symbol]
    attr_accessor :value

    # Return a new instance of Vedeu::Style.
    #
    # @param value [Array<String|Symbol>|String|Symbol]
    #   The style value or a collection of values.
    # @return [Style]
    def initialize(value = nil)
      @value = value
    end

    # Return an attributes hash for this class.
    #
    # @return [Array<String|Symbol>|String|Symbol]
    def attributes
      {
        style: value
      }
    end

    # Return the terminal escape sequences after converting the style or styles.
    #
    # @return [String]
    def to_s
      return '' unless defined_value?(value)

      @sequences ||= Array(value).flatten.map { |v| Vedeu::Esc.string(v) }.join
    end
    alias_method :escape_sequences, :to_s

  end # Style

end # Vedeu

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
vedeu-0.4.13 lib/vedeu/output/style.rb
vedeu-0.4.12 lib/vedeu/output/style.rb
vedeu-0.4.11 lib/vedeu/output/style.rb
vedeu-0.4.10 lib/vedeu/output/style.rb
vedeu-0.4.9 lib/vedeu/output/style.rb
vedeu-0.4.8 lib/vedeu/output/style.rb