Sha256: 0865c8770645bf051f561bd0176335242d0e96e354fdc188333f657fdac46aaf

Contents?: true

Size: 968 Bytes

Versions: 2

Compression:

Stored size: 968 Bytes

Contents

module CliSpinnable
  class Line
    class Sign
      using ColourableString

      class Error < CliSpinnableError; end

      SPIN = %w(- \\ | /).freeze
      TICK = "\u2713".green.freeze
      FAIL = "\u00d7".red.freeze
      BLANK = ''.freeze

      AVAILABLE_SIGNS = %i(spin tick fail blank).freeze

      def initialize(sign = nil)
        self.sign = sign || :blank
      end

      def sign=(sign)
        raise Error, "Unavailable sign: #{sign || 'nil'}" unless AVAILABLE_SIGNS.include?(sign)
        @sign = sign
        self
      end

      def to_s
        send(sign) + separator
      end

      private

      attr_reader :sign

      def separator
        sign == :blank ? '' : ' '
      end

      def spin
        spinner_enum.next
      end

      def tick
        TICK
      end

      def fail
        FAIL
      end

      def blank
        BLANK
      end

      def spinner_enum
        @spinner_enum ||= SPIN.cycle
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cli_spinnable-0.2 lib/cli_spinnable/line/sign.rb
cli_spinnable-0.1 lib/cli_spinnable/line/sign.rb