Sha256: cb8411fee517e0dbbbeb4414efbe6ad83e8b68bb975772045b79c9f5c61ed9a0

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

require 'vedeu/support/esc'

module Vedeu

  # Represents the concept of a visible or invisible attribute.
  #
  class Visible

    # @param visible [Boolean|Symbol]
    # @return [Visible]
    def self.coerce(value)
      if value.is_a?(self)
        value

      else
        new(value)

      end
    end

    # @param visible [Boolean|Symbol]
    # @return [Visible]
    def initialize(visible = nil)
      @visible = if visible == :hide || visible == false
        false

      elsif visible == :show || visible == true
        true

      else
        !!visible

      end
    end

    # @return [String]
    def cursor
      if visible?
        Esc.string('show_cursor')

      else
        Esc.string('hide_cursor')

      end
    end

    # @return [Boolean]
    def visible?
      @visible
    end

    # @return [Boolean]
    def invisible?
      !@visible
    end

    # @return [Visible]
    def hide
      Visible.new(false)
    end

    # @return [Visible]
    def show
      Visible.new(true)
    end

    # @return [Visible]
    def toggle
      visible? ? hide : show
    end

  end # Visible

end # Vedeu

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vedeu-0.4.2 lib/vedeu/support/visible.rb